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 ??Answer1:
<a href="http://msdn.microsoft.com/en-us/library/ms178116%28v=vs.100%29.aspx" rel="nofollow">This page</a> has pretty much everything you might need to know about resolving paths in ASP .NetAnswer2:
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);