Can't export to PDF

Bill Humphrey

Active member
Joined
Apr 10, 2008
Messages
35
Programming Experience
Beginner
Hi I can't export a datagrid to pdf, I keep getting the following error:

dobe reader could not open filename[1].pdf because it is either not a supported file type or because the file has been damaged

I'm using VS2008 and here is my code:

Dim dtaFinal As New DataGrid()
dtaFinal.DataSource = lResultCollection
dtaFinal.DataBind()

dtaFinal.HeaderStyle.ForeColor = System.Drawing.Color.White
dtaFinal.HeaderStyle.BackColor = System.Drawing.Color.DarkGray
dtaFinal.ItemStyle.BackColor = System.Drawing.Color.White
dtaFinal.AlternatingItemStyle.BackColor = System.Drawing.Color.AliceBlue

'---Create the File---------
Response.Buffer = True
Response.ClearContent()
Response.ClearHeaders()

'---For PDF uncomment the following lines----------
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment;filename=JobRequests.pdf")

EnableViewState = False

Dim sw As New StringWriter()
Dim hw As New HtmlTextWriter(sw)

'---Renders the DataGrid and then dumps it into the HtmlTextWriter Control
dtaFinal.RenderControl(hw)

'---Utilize the Response Object to write the StringWriter to the page
Response.Write(sw.ToString())
Response.Flush()
Response.Close()
Response.End()

Regards Bill Humphrey
 
Back
Top