Specification of relative resource paths in ASP.NET projects
I am in the process of getting an ASP.NET website project under version control, but am having some difficulty adapting my code from a one computer setup to a multiple-editor setup.
Currently, there are strings in this project that load resources by specifying an absolute path (e.g. "C:\Users...\file.ext") Obviously, the working copies of the project will not be the same for each user's computer, and 开发者_运维问答so this path needs to change. Is there any way to specify the location of that resource relative to the root of the project? I tried using ~, but that does not seem to work.
Thanks!
Have you tried mapping the relative path to a physical path:
public ActionResult Foo()
{
string fooBarLocation = Server.MapPath("~/App_Data/foo.bar");
// at this stage fooBarLocation will probably resemble something like this:
// c:\users\foo\bar\mysite\App_Data\foo.bar
// TODO: do something with this foo.bar file
// like for example reading its contents
}
精彩评论