Demetri avait écrit le 31.07.2006 :
No tangible example but its not that hard.
You have a web folder setup where the file will be written out to. Make sure
permissions are setup for ASPNet User to write out the files there.
Your method that extracts the data from the grid then converts that data to
an excel format (most common is CSV) and then outputs it to a file in the web
folder mentioned above.
Then at the end of that method it does a Redirect to that file.
--
-Demetri
"Amirallia" wrote:
>Demetri a formulé la demande :
>>You could write it out to disk and then redirect to it, providing the
directory the file is written to is a virtual one.
--
-Demetri
"Amirallia" wrote:
Hello
Here's my code to export a datagrid to Exel :
Response.Clear()
Response.Buffer = True
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
Dim monStringWriter As StringWriter = New StringWriter
Dim monHtmlTextWriter As HtmlTextWriter = New
HtmlTextWriter(monStringWriter)
monDG.RenderControl(monHtmlTextWriter)
Response.Write(monStringWriter.ToString())
Response.End()
It's work perfectly, but when my datagrid displays for exeample 10000
rows,
the export doesn't work.
Instead I have the page impossible to display !!!!
Any idea ?
Do you have an example ?
Thanks
sorry but it makes the same thing, directly redirect to a white page.
If I put a break point in my code, when I click on the button, It'
doesn't stop... Here'is my code
Dim Separator As String = ";"
Dim lLigne, lCol As Integer
Dim item As DataGridColumn
Dim strValeur As String
Dim monStreamWriter As System.IO.StreamWriter = New
System.IO.StreamWriter(Server.MapPath("./") & "upload\xxx.csv")
Try
For Each item In dg.Columns
monStreamWriter.WriteLine(item.HeaderText & Separator)
Next item
monStreamWriter.WriteLine(ControlChars.NewLine)
For lLigne = 1 To Me.dg.Items.Count - 1
For lCol = 0 To Me.dg.Items(lLigne).Cells.Count - 1
If Me.dg.Items(lLigne).Cells(lCol).Text = " "
Then
strValeur = ""
Else
strValeur =
Me.dg.Items(lLigne).Cells(lCol).Text
End If
strValeur = strValeur & Separator
Next
monStreamWriter.WriteLine(strValeur & Separator)
monStreamWriter.WriteLine(ControlChars.NewLine)
Next
monStreamWriter.Close()
Response.Redirect("Upload\xxx.csv")