i have loaded information into listview control but i want to create .csv file for listview control using listview subitem. in that time automatically create csv file to specific subitem to specific file.please help me this is very urgent i dont have time please
Create .csv file to listview subitem
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Nishant MittalRank #692 · 3.5K reputationPosted Nov 14, 2015, 2:57 AM EST
class ListViewToCSV { public static void ListViewToCSV(ListView listView, string filePath, bool includeHidden) { //make header string StringBuilder result = new StringBuilder(); WriteCSVRow(result, listView.Columns.Count, i => includeHidden || listView.Columns[i].Width > 0, i => listView.Columns[i].Text); //export data rows foreach (ListViewItem listItem in listView.Items) WriteCSVRow(result, listView.Columns.Count, i => includeHidden || listView.Columns[i].Width > 0, i => listItem.SubItems[i].Text); File.WriteAllText(filePath, result.ToString()); } private static void WriteCSVRow(StringBuilder result, int itemsCount, Func isColumnNeeded, Func columnValue) { bool isFirstTime = true; for (int i = 0; i result.Append(","); isFirstTime = false; result.Append(String.Format("\"{0}\"", columnValue(i))); } result.AppendLine(); } }Nishant MittalRank #692 · 3.5K reputationPosted Nov 14, 2015, 3:00 AM EST