Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to read xml files from App.config file path?


How to read xml files from App.config file path?

Author
Message
iramasani 51018
iramasani 51018
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 8
I have been on working windows console application to import xml data into database.
I am new to console applications,
I have a task i.e i want to import xml data from folders(which are created and saved xml files ex:c:\Projects\XMLfolder\folder\abc.xml, c:\Projects\XMLfolder\folder1\xyz.xml,)
for this i don't want to hard code, the file path for this just add key/value in the app.config file. Based on file path how to read xml files one by one(if exist file folder) if not exist xml file in current folder go next folder read the file if exist, after completion of reading file in a folder file need to move into another folder based on path mentioned in app.config.
How would i achieve this?
dmbaker
dmbaker
Mr or Mrs. 500
Mr or Mrs. 500 (575 reputation)Mr or Mrs. 500 (575 reputation)Mr or Mrs. 500 (575 reputation)Mr or Mrs. 500 (575 reputation)Mr or Mrs. 500 (575 reputation)Mr or Mrs. 500 (575 reputation)Mr or Mrs. 500 (575 reputation)Mr or Mrs. 500 (575 reputation)

Group: General Forum Members
Points: 575 Visits: 3440
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).



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search