Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to read all files inside particular folder

Tags:

c#

file

xml

I want to read all xml files inside a particular folder in c# .net

XDocument doc2 = XDocument.Load((PG.SMNR.XMLDataSourceUtil.GetXMLFilePath(Locale, "Products/category/product.xml"))); 

i have multiple products in category folder.. want loop the folder and should get all product xml file names.

XDocument doc2 = XDocument.Load((PG.SMNR.XMLDataSourceUtil.GetXMLFilePath(Locale, "Products/category/x1.xml"))); 
like image 217
ram Avatar asked Apr 30 '11 07:04

ram


People also ask

How do I read all files in a folder in R?

To list all files in a directory in R programming language we use list. files(). This function produces a list containing the names of files in the named directory. It returns a character vector containing the names of the files in the specified directories.


1 Answers

using System.IO; ... foreach (string file in Directory.EnumerateFiles(folderPath, "*.xml")) {     string contents = File.ReadAllText(file); } 

Note the above uses a .NET 4.0 feature; in previous versions replace EnumerateFiles with GetFiles). Also, replace File.ReadAllText with your preferred way of reading xml files - perhaps XDocument, XmlDocument or an XmlReader.

like image 50
Marc Gravell Avatar answered Sep 30 '22 06:09

Marc Gravell