Dim csvFilename as string = "C:\Temp\test.csv"
Dim stringArray() As String = {"this", "is", "a", "csv", "array"}
Private Sub BtnTestClick(sender As System.Object, e As System.EventArgs)
Dim csvOutput As New system.Text.StringBuilder()
' Add each string from the array to the stringbuilder
For index As Integer = 0 To Me.stringArray.Length - 1
If csvOutput.Length > 0 Then
csvOutput.Append(",")
End If
csvOutput.Append(stringArray(index))
Next
Dim csvOutputStream as System.IO.FileStream
Dim csvOutputWriter As System.IO.StreamWriter
Try
csvOutputStream = New System.IO.FileStream(Me.csvFilename, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None)
csvOutputWriter = new System.IO.StreamWriter(csvOutputStream)
csvOutputWriter.WriteLine(csvOutput.tostring())
Catch exc As exception
MessageBox.Show(exc.ToString(), "File Output Error")
Finally
If Not csvOutputWriter Is Nothing Then
csvOutputWriter.Flush()
csvOutputWriter.Close()
End if
End Try
End Sub