Solved

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

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
VB.Net - Find String in Array 3 26
How to open a link from vb.net app 3 10
Create XML 5 34
Protecting vb6 & .Net code Obfuscation 18 56
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now