开发者

getting the path of a file in .Net library

开发者 https://www.devze.com 2023-01-18 07:19 出处:网络
My library project is trying to open an XmlDocument from a file that\'s also contained in the library. How do I get the path of a file in the library so I can open it?

My library project is trying to open an XmlDocument from a file that's also contained in the library. How do I get the path of a file in the library so I can open it?

The current directory is not useful and Server.MapPath returns me the path of the main web application (MVC), so how do I get the path of the file in the library?

------- Edit The xml files are in a folder within the library project which wont exist when deployed. So it seems these files need to exist in a folder outside of the library (in开发者_StackOverflow中文版 a virtual directory in IIS for instance).

Steve


If you're looking for the path of the currently-executing program or assembly (I'm not sure that you are), use the Location property of the Assembly you're interested in:

string path = Assembly.GetExecutingAssembly().Location;

or

string path = Assembly.GetAssembly(typeof(TypeInAssembly)).Location;
0

精彩评论

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