Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
ASP .Net
Gridview to CSV
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
Reply to thread
Message
[QUOTE="Vincent, post: 1917974"] Thanks that pointed me in the right direction and I've gotten this to work... Here's the code I used: ******************************************* Dim objStreamWriter As IO.StreamWriter 'Pass the file path and the file name to the StreamWriter constructor. 'make sure this is a path that you have permissions to save in objStreamWriter = New IO.StreamWriter("c:\myfiles\mycsvfile.csv") 'Write text. Dim Str As String Dim i As Integer Dim j As Integer Dim headertext = "field1,field2,field3,field4,field5,field5,field6" objStreamWriter.WriteLine(headertext) For i = 0 To (Me.GridView2.Rows.Count - 1) For j = 0 To (Me.GridView2.Columns.Count - 1) 'this IF statement stops it from adding a comma after the last field If j = (Me.GridView2.Columns.Count - 1) Then Str = (Me.GridView2.Rows(i).Cells(j).Text.ToString) Else Str = (Me.GridView2.Rows(i).Cells(j).Text.ToString & ",") End If objStreamWriter.Write(Str) Next objStreamWriter.WriteLine() Next 'Close the file. objStreamWriter.Close() ******************************************************* [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
ASP .Net
Gridview to CSV
Top