开发者

ASP.Net MVC2: Where can I store a file to be able to access it on both my dev box and in production?

I need to store a file, such that my ASP.Net MVC app开发者_高级运维 can access the file, both when I run the website in visual studio, and when the production server is actually running. I don't think that I can do relative pathing on my dev box, because the execution path is something in the System32 folder. I don't know if the same is true on the server, but either way, an absolute path is not an option.

Is there a way that I can refer to this file in code, that will work for both my dev box and my production server?


If you can store the file within your application hierarchy, you can do this:

Server.MapPath("~/path/to/file")

Alternatively, you can get the path of the currently executing assembly like so:

string codeBase = Assembly.GetExecutingAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path);

And construct your relative path from that.


Try a subfolder of the:

Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData))
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜