0
我有下面的代碼:文件,擴展名的.msg不下載
Dim filePath As String = Request.QueryString("FilePath")
Dim fileName As String = filePath.Substring(filePath.LastIndexOf("/") + 1)
Dim ext As String = Path.GetExtension(fileName)
'If (ext = ".xls") Then
' Response.ContentType = "application/vnd.ms-excel"
'ElseIf (ext = ".xlsx") Then
' Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
'End If
If ext = ".msg" Then
Response.ContentType = "application/octet-stream"
'Response.ContentType = "application/vnd.ms-outlook"
ElseIf (ext = ".xls") Then
Response.ContentType = "application/vnd.ms-excel"
ElseIf (ext = ".xlsx") Then
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
End If
'fileName = Server.MapPath("~\\files\\RAP_Batch_Upload_form.xls")
Response.AppendHeader("Content-Disposition", "attachment;filename=" & fileName)
'Response.AddHeader("Content-Length", New System.IO.FileInfo(fileName).Length)
'Response.AddHeader("Content-Length", New System.IO.FileInfo("Batch_test_11.xlsx").Length)
Response.Redirect(filePath)
Response.End()
我能夠下載帶有.xls和的.xlsx文件,但.msg文件的文件會給找不到網頁的錯誤。這些文件存儲在附件文件夾中,示例文件路徑看起來像http://our.domain.com/Attachment/2017123456 Demo_Re.msg(空間是文件名的一部分,對於.xls和.xlsx文件不是問題)。
有人能告訴我我錯過了什麼。
好吧我需要將.msg添加到IIS,直到那時我不能正常工作?我應該只在IIS中添加它還是在web.config中添加 staticContent>是否足夠? –
我只有通過IIS添加它,所以不能評論web.config。 – levis84
我的意思是application/vsd.ms-outlook。我添加到web.config。它不工作。我正在VS 2015 IIS Express中測試。 –