writealltext vb.net web form

1.4k views Asked by At

How to: Write Text to Files in Visual Basic

I am trying to use this procedure to export data from a datatable into a csv file. I have got the data from the table ready in a string and am trying to use the following code to write in to a file (I did want to use excel, but gave up so trying to use a csv file). I am not getting an error, but the file is not appearing either, my string is definitly not empty though. Any help/direction appreciated.

Dim str As New StringBuilder
        For Each dr As DataRow In objDS.Tables("dt_export").Rows
            For Each field As Object In dr.ItemArray
                str.Append(field.ToString & ",")
            Next
            str.Replace(",", vbNewLine, str.Length - 1, 1)
        Next
        Try
            Response.Write(str.ToString)
            My.Computer.FileSystem.WriteAllText("C:\temp\testcsv.csv", str.ToString, False)

        Catch ex As Exception
            Response.Write("Write Error")
        End Try
0

There are 0 answers