?
Solved

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

Posted on 2006-12-01
2
Medium Priority
?
182 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

762 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