[ACCEPTED]-.msg file gives download error-http-status-code-404

Accepted answer
Score: 19

Found on ASP.NET forum.

Create a handler, download 5 it as a file:

Response.ContentType = "application/vnd.ms-outlook";
Response.AppendHeader("Content-Disposition","attachment; filename=Message.msg");
Response.TransmitFile(Server.MapPath(YourPathToMsgFile));
Response.End();

or change the setting in IIS 4 6.0:

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

Score: 7

using this tag below we can directly mention 3 the file name to the tag.

   <a href="Your File_Location">Download Link</a>

no need to specify 2 the code in the controller.

just add below 1 tag to web.config inside

  <staticContent>
    <mimeMap fileExtension=".msg" mimeType="application/octet-stream" />
</staticContent>
Score: 3
<system.webServer>   
    <staticContent>
      <mimeMap fileExtension=".msg" mimeType="application/octet-stream" />
    </staticContent>
</system.webServer>

0

Score: 1

Here is the another response that I found 7 on ASP.NET Forum. Included here to as time 6 saver.

If ASP.NET Core is handling the static 5 content itself and is running at the edge, or 4 if you need ASP.NET Core to be aware of 3 mime types, you need to configure ASP.NET 2 Core's handler to be aware of it using FileExtensionContentTypeProvider 1 like below :

public void Configure(IApplicationBuilder app)
{
    // Set up custom content types - associating file extension to MIME type
    var provider = new FileExtensionContentTypeProvider();
    // Replace an existing mapping
    provider.Mappings[".msg"] = "application/vnd.ms-outlook";

    app.UseStaticFiles(new StaticFileOptions
    {
        FileProvider = new PhysicalFileProvider(
            Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "images")),
        RequestPath = "/StaticContentDir",
        ContentTypeProvider = provider
    });

Credits Sherry Chan

ASPNET Forum LINK

More Related questions