how to set path to a file in ASP C# properly?

♀尐吖头ヾ 提交于 2019-12-12 01:35:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!