0

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 ??

Mikkel Eriksen
  • 69
  • 3
  • 15

2 Answers2

2

This page has pretty much everything you might need to know about resolving paths in ASP .Net

FlyingStreudel
  • 4,434
  • 4
  • 33
  • 55
0

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);
Ali Umair
  • 1,386
  • 1
  • 21
  • 42