Solved

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

Posted on 2006-12-01
2
174 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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Write to a printer using vb.net 9 40
ASP/VB email question 4 46
Access Schema 6 26
vb.net convert long time to mm:ss 23 13
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

829 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