扩展名为.msg的文件无法下载

时间:2017-05-11 12:47:32

标签: vb.net visual-studio-2008 asp.net-3.5

我有以下代码:

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文件会给出找不到页面的错误。这些文件存储在Attachments文件夹中,示例filePath看起来像http://our.domain.com/Attachment/2017123456 Demo_Re.msg(Space是fileName的一部分,对于.xls和.xlsx文件来说也不是问题。)

有人可以告诉我我错过了什么。

1 个答案:

答案 0 :(得分:1)

打开IIS,选择您网站的属性

选择HTTP标头 - >点击MIME类型 - >单击New并将“.msg”添加为扩展名,将“application / vsd.ms-outlook”添加为MIME类型。