views:

269

answers:

3

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

+1  A: 
String  virtualPath= "~\\images";
String RealPath=Server.MapPath(virtualPath); //it must be done at web application
System.IO.DirectoryInfo directory= new System.IO.DirectoryInfo(RealPath);
Sessiz Saat
+1  A: 

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);
Arjan Einbu
Yes, thats right the folder is named images, relative to my app it is ../imagesWould I use ../images as the relativeFileName ? Thanks very much.
I'm a bit unsure about the ../ in the path, but I think it should work...
Arjan Einbu
Don't worry about the "/", rather use Path.Combine, since it is Platform agnostic and takes care of separators for you.
bingle
+1  A: 

new DirectoryInfo(Path.Combine(Server.MapPath(Request.ApplicationPath), "images"));

bingle