Home Forums Programming General How to read xml files from App.config file path? RE: How to read xml files from App.config file path?

  • Can you post more details? Sounds like you're using .NET (since you mention app.config) but knowing what language you're coding would be helpful (e.g. c#? VB.NET?) as would what version of .NET you're using.

    That said, what you're asking about is pretty standard functionality in .NET. For the app.config part, just add your XML file paths as appSettings in the app.config file, then read them back out.

    http://msdn.microsoft.com/en-us/library/aa735785(v=vs.71).aspx

    http://forums.asp.net/t/1168194.aspx

    This isn't the only way to handle configuration data, but it's the simplest and it's baked right into .NET and might serve your needs. If you want to put a variable set of paths in your config then you might be better off with a custom configuration section, but that isn't necessarily needed depending on how you set up your appSetting (e.g. if you have a setting that says how many path elements you have, and you number the actual path elements, you could handle it "by convention").

    OK, that's for setting up the app.confiig. Now how to actually read it and process your XML files? Do you already know how to open/read an XML file in .NET? Xml-handling code is in the System.Xml and related assemblies -- when you start a new console app project in Visual Studio, System.Xml should be automatically added to project references for you.

    To open and process your files you have a couple of options: XmlDocument and XmlReader. Read up on these regarding how and when to use them. Basically, you load up a document and then read through it, and process the data in the document however you need to do so, to meet your requirements. If yo're dealing with huge documents, you'll want to use XmlReader. For small/simle documents, XmlDocument is probably better.

    You don't say what you intend to do with the XML documents, but note that if you're just wanting to load the data into a database then using an app to do it isn't your only choice (and may not be the best choice either).