开发者

Specification of relative resource paths in ASP.NET projects

开发者 https://www.devze.com 2023-03-07 17:40 出处:网络
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.

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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消