Showing posts with label LINQ. Show all posts
Showing posts with label LINQ. Show all posts

Wednesday, September 23, 2009

CSV to XML Conversion using LINQ

on C#, if we want to Convert CSV to XML then you can use Language Integrated Query (LINQ) can be used to convert a CSV file to XML. Here is the sample CSV file that needs to be converted

below example code reads the CSV file to an array. LINQ is used to loop through the array and the contents are written as XML using XElement (System.XML.Linq).


public void ConvCSVToXML()

{

String[] FileContent = File.ReadAllLines(@"D:\Proj\jquery.csv");

String XMLNS = "";

XElement Inv = new XElement("type", from

items in FileContent

let fields = items.Split(',')

select new XElement("fadein",

new XElement("Tab", fields[0]),

new XElement("ProgressBar", fields[1]),

new XElement("ToolTip", fields[2]),

new XElement("Menu", fields[3]),

)
);

File.WriteAllText(@"D:\Proj\jquery.xml", XMLNS + Inv.ToString() );
}


using this you can convert your CSV file xml using C# and C# Convert CSV To XML, .NET CSV To XML

Tuesday, June 30, 2009

The LINQ Project

The LINQ Project is a codename for a set of extensions to the .NET Framework that encompass language-integrated query, set, and transform operations.


It extends C# and Visual Basic with native language syntax for queries and provides class libraries to take advantage of these capabilities


LINQ Project