I am getting the below error message when I try to convert Gridview to pdf format. can someone help me.
thank you
here is the code
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'Get the HTML from GridView1
Dim sw As New IO.StringWriter()
Dim htw As New HtmlTextWriter(sw)
gvSearch.RenderControl(htw)
Dim html As String = "<html><body>" + sw.ToString() + "</body></html>"
'Set up the response
Response.Clear()
Response.ContentType = "application/pdf"
'Create pdf document
Dim document As New iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 80, 50, 30, 65)
'Create pdf writer, output directly to OutputStream
Dim writer As iTextSharp.text.pdf.PdfWriter = PdfWriter.GetInstance(document, Response.OutputStream)
document.Open()
'Create tempfile to hold the HTML:
Dim tempFile As String = Path.GetTempFileName()
Using tempwriter As New IO.StreamWriter(tempFile, False)
tempwriter.Write(html)
End Using
'Parse the HTML into the document
iTextSharp.text.html.HtmlParser.Parse(document, tempFile)
'Cleanup
document.Close()
writer.Close()
'Delete the tempfile:
File.Delete(tempFile)
writer = Nothing
document = Nothing
Response.[End]()
End Sub
Security Exception
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.
Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
Source Error:
Line 281:
Line 282: 'Parse the HTML into the document
Line 283: iTextSharp.text.html.HtmlParser.Parse(document, tempFile)
Line 284:
Line 285: 'Cleanup
thank you
here is the code
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'Get the HTML from GridView1
Dim sw As New IO.StringWriter()
Dim htw As New HtmlTextWriter(sw)
gvSearch.RenderControl(htw)
Dim html As String = "<html><body>" + sw.ToString() + "</body></html>"
'Set up the response
Response.Clear()
Response.ContentType = "application/pdf"
'Create pdf document
Dim document As New iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 80, 50, 30, 65)
'Create pdf writer, output directly to OutputStream
Dim writer As iTextSharp.text.pdf.PdfWriter = PdfWriter.GetInstance(document, Response.OutputStream)
document.Open()
'Create tempfile to hold the HTML:
Dim tempFile As String = Path.GetTempFileName()
Using tempwriter As New IO.StreamWriter(tempFile, False)
tempwriter.Write(html)
End Using
'Parse the HTML into the document
iTextSharp.text.html.HtmlParser.Parse(document, tempFile)
'Cleanup
document.Close()
writer.Close()
'Delete the tempfile:
File.Delete(tempFile)
writer = Nothing
document = Nothing
Response.[End]()
End Sub
Security Exception
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.
Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
Source Error:
Line 281:
Line 282: 'Parse the HTML into the document
Line 283: iTextSharp.text.html.HtmlParser.Parse(document, tempFile)
Line 284:
Line 285: 'Cleanup