Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
See more:
Hi All,


Here i wanna save listview items stored in xml file using c# windows application. Am using Visual Studio 2008. All replies welcome...

Thanks & Regards,

Dhinesh Kumar.V
Posted

if you populated list view via datatable then you just need to call DataTable.WriteXML method (Don't forget to Set DataTable.Name once),

if it is via other way like List<string> or Items.add then you have to manually implement serializer class for achieve this
 
Share this answer
 
XML
XElement xeRoot = new XElement("Data");
           XElement xeSubRoot = new XElement("Rows");
           foreach (var items in listView1.Items)
           {

               XDocument document = new XDocument(new XElement("Data", from item in listView1.Items.Cast<ListViewItem>()
                                                                       select new XElement("Proc", item.SubItems.Cast<System.Windows.Forms.ListViewItem.ListViewSubItem>().Select((subitem, i) => new XElement(
                                                                           i == 0 ? "PName":listView1.Columns[i].Text.ToLower(), subitem.Text)))));
               document.Save("sample.xml");
           }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900