我正在尝试访问我的应用程序中的路径。从frm_VerifyIndentity.aspx.cs到Imgs文件夹。
我正在使用下面的代码:
string pathRepositories = Request.ApplicationPath + "/IVT/Imgs/";
其中Request.ApplicationPath的值为
/ IVT
我将此参数传递给
DirectoryInfo directory = new DirectoryInfo(pathRepositories);
FileInfo[] files = directory.GetFiles("*.jpg");
pathRepositories是串联的地方:
/ IVT / IVT / IMGS /
但是,奇怪的是,因为当我检查目录所在的值时,值将在下面
C:\IVT\IVT\Imgs\ instead of my pathapplication.
这就是为什么我接下来的错误:
有人知道为什么吗?
答案 0 :(得分:0)
使用此属性构建相对于应用程序根目录的URL 来自不在根目录中的页面或Web用户控件。
因此ApplicationPath
为您提供相对路径,并将其视为绝对路径。
使用您当前的方法,您可能对HttpRequest.PhysicalApplicationPath
感兴趣,但我不确定这是否合理。
另外,请考虑使用Path.Combine
而不是自己连接字符串。