Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.msg file gives download error

In my application, I keep some files on server and make them available for download on some business logic.

All other file types are getting downloaded but .msg(Outlook message) file do not get downloaded and gives Error:

404 - File or directory not found. The resource you are looking for might
have been removed, had its name changed, or is temporarily unavailable.

Images, .docx, .txt all other files are working well.

The page is designed in ASP.NET and at client site following mark up comes.

like image 588
MaxRecursion Avatar asked Mar 15 '12 10:03

MaxRecursion


People also ask

Why can't I open a MSG file?

msg file not opening in outlook” issue is to open the file manually. In some cases, Outlook is not the default email client, so there is no relevant application to open the MSG file. Right-click on the MSG file on your system. Choose “Open with” and select Outlook(desktop) option.

How do I download a .MSG file from email?

Double-click to open the message you want to save, and on the File menu, click Save As. In the Save as dialog box, in the Folder pane, choose a folder, and then the location in that selected folder where you want to save the file.

How do I convert MSG files to Outlook?

Right-click any file with an . msg file name extension, point to Open with and then click Choose default program. In the Open with dialog box, select Always use the selected program to open this kind of file. Then, select Outlook (desktop) and then click OK.


2 Answers

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

If ASP.NET Core is handling the static content itself and is running at the edge, or if you need ASP.NET Core to be aware of mime types, you need to configure ASP.NET Core's handler to be aware of it using FileExtensionContentTypeProvider 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

like image 99
Avi Avatar answered Oct 27 '22 06:10

Avi


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

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

no need to specify the code in the controller.

just add below tag to web.config inside

  <staticContent>
    <mimeMap fileExtension=".msg" mimeType="application/octet-stream" />
</staticContent>
like image 22
JKANNAN Avatar answered Oct 27 '22 05:10

JKANNAN