I'm trying to access to the path in my application.From frm_VerifyIndentity.aspx.cs to Imgs folder.
I'm using next below code:
string pathRepositories = Request.ApplicationPath + "/IVT/Imgs/";
where the value of Request.ApplicationPath is
/IVT
And I pass this parameter to
DirectoryInfo directory = new DirectoryInfo(pathRepositories);
FileInfo[] files = directory.GetFiles("*.jpg");
Where the pathRepositories is concatenation:
/IVT/IVT/Imgs/
But, the strange, because when I check the value where the directory is looking for, the values is next below
C:\IVT\IVT\Imgs\ instead of my pathapplication.
Thta's why I get next below error:
Somebody know why?
From the documentation:
So
ApplicationPath
gives you relative path, and you're treating it as an absolute path.With your current approach you could be interested with
HttpRequest.PhysicalApplicationPath
, but I'm not sure if this is sound.Also, consider using
Path.Combine
instead of concatenating strings yourself.