ASP.NET relative path
I have an ASP.NET project I'm currently working on. There is a C# file (dbedit.cs) that is used to directly access and edit 2 XML database files. How can I create a relative path of the XML files (both in the same directory) to dbedit.cs? It needs to be portable so it can't be hard-coded in. dbedit.cs is also accessed from two other projects that are in the same solution, so the assembly path of dbedit.cs is different depending on which project is accessing开发者_运维问答 it.
This doesn't work for that reason:
(new System.Uri(Path.GetDirectoryName(Assembly.GetAssembly(typeof(dbedit)).CodeBase))).LocalPath;
Any help would be greatly appreciated.
You can use something like HttpContext.Current.Server.MapPath
. This needs to be a web-project though.
[Edit] Here are documentation for MapPath: http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath.aspx
精彩评论