Hi There!

I'm working with application for adding contacts using Visual Basic 2012. The application have textboxes to add data, control buttons and ListView to display contents in columns. I want to save the information in listView box where a user click save button and savedialogbox open in order to choose file path. I'm unable to get it right with the code I wrote and it's as follows:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim iSave As New SaveFileDialog
    iSave.Filter = "txt Files (*.txt) |*.txt"
    iSave.FilterIndex = 2
    iSave.RestoreDirectory = False
    If iSave.ShowDialog() = Windows.Forms.DialogResult.OK Then
        IO.File.WriteAllText(iSave.FileName, ListViewItemCollection)
    End If

You have to iterate through all of the items in the listview collection and convert them to string before you write them out. If the collection is small then you can create the output buffer in a loop then use WriteAllText to blast it out in one step. I suggest you use a StringBuilder object to do this as it efficiently concatenates strings whereas just concatinating many regular strings is very inefficient. If you have a large listview collection then you can open the output file as a stream and write the lines one by one,