Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
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 …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

598 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