Solved

How do I copy all items in a listview to a text file?

Posted on 2006-12-01
2
175 Views
Last Modified: 2010-04-23
I want to be able to click a button that takes all items and subitems in a listview and copies them to a comma delimited textfile. I have absolutely no idea how to do this so would appreciate any help with this.

textfile path c:\ListView
textfile name: lstMenu.txt

the listview name is lstMenu

item column name: PooX
subItem1 column name: Value
subitem 2 column name: Code 1
subItem 3 column name: Code 2

I do not need the column header names copied just the contents of the listview. I row of listview = 1 row of comma delimited text

Thanks

PBLack
0
Comment
Question by:PBLack
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

by:
riyazthad earned 500 total points
ID: 18056767
Here it is

    Private Sub Button1_Click_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim s As String = "C:\ListView\lstMenu.txt"

        Dim fs As IO.FileStream

        If IO.File.Exists(s) Then
            fs = New IO.FileStream(s, IO.FileMode.Append)
        Else
            fs = New IO.FileStream(s, IO.FileMode.CreateNew)
        End If

        Dim f As New IO.StreamWriter(fs)
        For Each i As ListViewItem In lstMenu.Items
            f.WriteLine(i.SubItems(0).Text & "," & i.SubItems(1).Text & "," & i.SubItems(2).Text)
        Next

        f.Close()

    End Sub

 Make sure you created folder 'ListView'

---

 If you want to create folder in runtime u can use this code

          If Not Directory.Exists("C:\LisView") Then
                Directory.CreateDirectory("C:\LisView")
            End If
0
 

Author Comment

by:PBLack
ID: 18059172
Thanks. Works great.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question