2

I have the below code :

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()

I am able to download the files with .xls and .xlsx files but .msg files will give page not found error. The files are stored in an Attachments folder and a sample filePath looks like http://our.domain.com/Attachment/2017123456 Demo_Re.msg (Space is part of the fileName and for .xls and .xlsx files that is not a problem).

Could anybody tell me what am I missing.

1 Answer 1

3

Open your IIS, select properties for your website

Select HTTP Header -> click MIME types - > Click New and add ".msg" as extension and "application/vsd.ms-outlook" as MIME type.

5
  • Okay I need to add .msg to IIS until then I won't work right? Should I add it in IIS only or adding <staticContent> <mimeMap fileExtension=".msg" mimeType="application/octet-stream" /> </staticContent> in web.config is sufficient? May 11, 2017 at 12:54
  • I have only ever added it via IIS so cannot comment on web.config.
    – levis84
    May 11, 2017 at 13:00
  • I meant application/vsd.ms-outlook. I added to web.config. Its not working. I am testing in VS 2015 IIS Express. May 11, 2017 at 13:01
  • Ok, iis changes are the way to go. I'm not familiar with iis express but you should get the option to add the mime type as I described
    – levis84
    May 11, 2017 at 13:04
  • Okay. Thanks. I will try :) May 11, 2017 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.