Hi Guys,
Hope you can help me with this.
I got a Grid with a GridTemplateColumn and other informational columns, and inside the GridTemplateColumn is a ImageButton that will execute a function that will open documents. Here is the code:
All work fine for the first time. But as soon I do a sorting of columns or filtering or change page, the Response.End() gives me an error of "Unable to evaluate expression". As a postback is made it start working again. Also I used HttpContext.Current.ApplicationInstance.CompleteRequest instead of Response.End() to see if continue working, in this case the error is not given, but still doesn't open the document. I know this is not a error of yours, but maybe there's something I could set to the grid to let me do what i need. Please let me know if you need any other information.
Thanks,
Josue
Hope you can help me with this.
I got a Grid with a GridTemplateColumn and other informational columns, and inside the GridTemplateColumn is a ImageButton that will execute a function that will open documents. Here is the code:
Public
Sub
OpenDocument(
ByVal
sAttachmentPath
As
String
)
Dim
sAttachmentExt
As
String
Response.Clear()
Response.ClearHeaders()
Response.ClearContent()
sAttachmentExt = sAttachmentPath.Substring(sAttachmentPath.LastIndexOf(
CChar
(
"."
)))
Try
Select
Case
sAttachmentExt
Case
".doc"
Response.ContentType =
"application/msword"
Case
".docx"
Response.ContentType =
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
Case
".xls"
Response.ContentType =
"application/vnd.ms-excel"
Case
".xlsx"
Response.ContentType =
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Case
".ppt"
Response.ContentType =
"application/vnd.ms-powerpoint"
Case
".pptx"
Response.ContentType =
"application/vnd.openxmlformats-officedocument.presentationml.presentation"
Case
".pdf"
Response.ContentType =
"application/pdf"
Case
".html"
Response.ContentType =
"application/html"
Case
".txt"
Response.ContentType =
"application/plain"
Case
".zip"
Response.ContentType =
"application/zip"
Case
".rar"
Response.ContentType =
"application/rar"
Case
".gif"
Response.ContentType =
"application/gif"
Case
".jpg"
Response.ContentType =
"application/jpeg"
Case
".png"
Response.ContentType =
"application/png"
Case
".swf"
Response.ContentType =
"application/x-shockwave-flash"
Case
".mpeg"
Response.ContentType =
"application/mpeg"
Case
".avi"
Response.ContentType =
"application/x-msvideo"
Case
Else
Response.ContentType =
"application/plain"
End
Select
Response.AddHeader(
"Content-Disposition"
,
"attachment;filename="
& sAttachmentPath)
Dim
sourcefile
As
FileStream =
New
FileStream(sAttachmentPath, FileMode.Open)
Dim
FileSize
As
Integer
FileSize = sourcefile.Length
Dim
getContent()
As
Byte
=
New
Byte
(FileSize - 1) {}
sourcefile.Read(getContent, 0,
CInt
(sourcefile.Length))
sourcefile.Close()
Response.BinaryWrite(getContent)
Response.Flush()
Catch
ex
As
Exception
Throw
ex
Finally
Response.
End
()
End
Try
End
Sub
All work fine for the first time. But as soon I do a sorting of columns or filtering or change page, the Response.End() gives me an error of "Unable to evaluate expression". As a postback is made it start working again. Also I used HttpContext.Current.ApplicationInstance.CompleteRequest instead of Response.End() to see if continue working, in this case the error is not given, but still doesn't open the document. I know this is not a error of yours, but maybe there's something I could set to the grid to let me do what i need. Please let me know if you need any other information.
Thanks,
Josue