2009-02-13 40 views
1

有没有人知道如何设置DirectoryInfo的路径,当我想映射到webRoot上名为images的文件夹时。 /图像.Net DirectoryInfo路径

任何帮助非常赞赏, 感谢

回答

3

如果你有相对于你的web应用程序的路径,你需要用MapPath方法(...)方法映射。

在页类:

string fullyQualifiedFilename = Server.MapPath(relativeFilename); 

或页面类以外:

string fullyQualifiedFilename = HttpContext.Current.Server.MapPath(relativeFilename); 
+0

是的,多数民众赞成在文件夹被命名为图像,相对于我的应用程序它是../images 我会使用../images作为relativeFileName吗?非常感谢。 – user17510 2009-02-13 08:16:39

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

新DirectoryInfo的(Path.Combine(使用Server.Mappath(Request.ApplicationPath), “图像”) );