问题
working on a website here, in ASP and C#.
my problem is, when I try to read a file, it finds the wrong directory. here are the code im using:
addtext.Text = new WebClient().DownloadString("readme.htm");
error look like this:
Could not find file 'C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\readme.htm'.
how do I guide the path to the same as my default.aspx ??
回答1:
This page has pretty much everything you might need to know about resolving paths in ASP .Net
回答2:
I suggest you to use app keys for saving the address of the folder which contains your files. You can build a hierarchy for different type of files.
<add key="WebResources" value="~/Assets/WebResources/" />
<add key="ImageRoot" value="Images\Web" />
and then access them like this and concatenate them with further folder of hierarchy .
string WebResources = ConfigurationManager.AppSettings["WebResources"];
string dir = System.Web.HttpContext.Current.Server.MapPath(WebResources);
来源:https://stackoverflow.com/questions/16423159/how-to-set-path-to-a-file-in-asp-c-sharp-properly