Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Reading XLSX files from web browser

Author  Topic 

saidev
Posting Yak Master

101 Posts

Posted - 2012-05-11 : 18:38:13
Hi Guys,

I am uploading ".xlsx" files to one of my web page in a calendar. While reading the file i am getting a message "Excel found unreadable content in 'test.xlsx' Do you want to recover the contents of the workbook? If i say YES then the content is loading properly. How to avoid this message while opening the xlsx files. I am able to open xls files normally. Here is my code. Can you guys advice on how to fix this issue? Thanks for your help.


If objDBReader.Read Then

If objDBReader("UploadFileType") = "doc" Then
Response.ContentType = "application/msword"
ElseIf objDBReader("UploadFileType") = "docx" Then
Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
ElseIf objDBReader("UploadFileType") = "htm" Then
Response.ContentType = "text/HTML"
ElseIf objDBReader("UploadFileType") = "rtf" Then
Response.ContentType = "application/msword"
ElseIf objDBReader("UploadFileType") = "txt" Then
Response.ContentType = "application/msword"
ElseIf objDBReader("UploadFileType") = "xls" Then
Response.ContentType = "application/vnd.ms-excel"
ElseIf objDBReader("UploadFileType") = "xlsx" Then
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
ElseIf objDBReader("UploadFileType") = "pdf" Then
Response.ContentType = "application/pdf"
ElseIf objDBReader("UploadFileType") = "ppt" Then
Response.ContentType = "application/vnd.ms-powerpoint"
ElseIf objDBReader("UploadFileType") = "pptm" Then
Response.ContentType = "application/vnd.ms-powerpoint"
Else
Exit Sub
End If

Response.AppendHeader("content-disposition", "attachment;filename=" + objDBReader("FileName"))


Response.Expires = 0
Response.Buffer = True
Response.Clear()

Response.BinaryWrite(objDBReader("UploadFile"))
objConn.Close()
Response.End()
End If

   

- Advertisement -