Does anyone know how to set the path for DirectoryInfo when I want to map to a folder named images on webRoot. /images
Any help much appreciated, Thanks
Does anyone know how to set the path for DirectoryInfo when I want to map to a folder named images on webRoot. /images
Any help much appreciated, Thanks
String virtualPath= "~\\images";
String RealPath=Server.MapPath(virtualPath); //it must be done at web application
System.IO.DirectoryInfo directory= new System.IO.DirectoryInfo(RealPath);
If you have a path relative to your web-app, you'll need to map it with the MapPath(...) method.
In the Page class:
string fullyQualifiedFilename = Server.MapPath(relativeFilename);
or outside of the page class:
string fullyQualifiedFilename = HttpContext.Current.Server.MapPath(relativeFilename);
new DirectoryInfo(Path.Combine(Server.MapPath(Request.ApplicationPath), "images"));