User-1578974752 posted
There is a pdf attachment in the gridview.I can open all other attachment except one(5).Each atachment is in each row of gridview.5th one, when i open below error message is coming
There was an error opening this document.The file is damaged and could not be repaired. How to solve this issue.
(When I open that PDF from its path(c:..)it is opening.)
Code as below:
If
UCase(Right(sFileName,
4)) = ".PDF"
Then
'set the http content type to "application/pdf"
HttpContext.Current.Response.ContentType = "application/pdf"
'Else
'set the http content type to "APPLICATION/OCTET-STREAM
HttpContext.Current.Response.ContentType = "APPLICATION/OCTET-STREAM"
End If '
'initialize the http content-disposition header to
' indicate a file attachment with the filename
Dim disHeader As String = "Attachment;
Filename=" & sFileName
HttpContext.Current.Response.AppendHeader("Content-Disposition", disHeader)
' transfer the file byte-by-byte to the response object
HttpContext.Current.Response.Flush()
HttpContext.Current.Response.WriteFile(objFileToBeLoad.FullName)
'HttpContext.Current.Response.End()
Try
HttpContext.Current.ApplicationInstance.CompleteRequest()
Catch ex As Exception
End Try