I have a virtual directory setup in IIS6. This maps to a shared network drive.
I can correctly map the path using
string mappedPath = HttpContext.Current.Server.MapPath(path);
I then create a DirectoryInfo object as I want to find some files in the directory.
DirectoryInfo updateDirectory = new DirectoryInfo(mappedPath);
But then updateDirectory.Exists is false?? I can take the string from the mappedPath and copy into Start->Run to get to the path so I know it exists. I am authenticating to the webservice using integrated windows authentication and have permissions to the necessary folders.
Is there something obvious I’m missing in the code? Or is this purely set-up and configuration of IIS etc.?
According to this link:
http://bytes.com/topic/asp-net/answers/471616-server-mappath-virtual-directories
Server.MapPathdoesn’t give expected output when used against virtual directories.If it is server permissions and you are using Windows Authentication, make sure you have this in your config:
DirectoryInfo returns false on error conditions: if the folder isn’t there; you don’t have permissions; or it’s a disconnected network folder.
Sounds like permissions of your ASP.NET worker process to me – the impersonation will solve this.