I’ve spent a couple hours trying to find a good answer to this.. How can i load an XML file into a class library. I’ve checked around for a concrete answer to this question, and if this has been asked, it isn’t worded in a way that led me to a decent answer.
I just need to be able to reference an XML file in a class library without a Web dependent reference.
I’ve got a project and I’m building a class Library which will be used for various functions, and in multiple manifestations of the app, desktop, web, in-house, etc… so i need to be able to rely on the path returned.
I’ve thought about putting the physical path as an AppSetting or similiar, but i’d prefer to not have to and just have the .xml file in the bin directory (copy always), and then reference it from there..
Assembly.GetExecutingAssembly().Location // base .net directory? windows/.net/...
AppDomain.CurrentDomain.BaseDirectory // based directory of app that references .dll
(maybe i’m misunderstanding / misusing the above?)
basically i want to reference the file. I know i’ve done this before, but at the moment it’s totally escaping me and i can’t find the resource that led me the way. I’m anticipating a bunch of references to other stack posts, and if one of them works, so be it, however, don’t send one that says HttpContext.Current is the solution
UPDATE:::
Thanks for the quick answers..
This kind of works, but i dont like needing to path into the app:
AppDomain.CurrentDomain.BaseDirectory + “\BIN\DataXML\TaskData.xml”;
I would use
AppDomain.CurrentDOmain.BaseDirectory. If you look at the documentation for Assembly.Location, you’ll see why it might not be appropriate.