Reputation: 4903
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.
Upvotes: 11
Views: 18373
Reputation: 300
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
Upvotes: 1
Reputation: 129
<system.webServer>
<staticContent>
<mimeMap fileExtension=".msg" mimeType="application/octet-stream" />
</staticContent>
</system.webServer>
Upvotes: 3
Reputation: 4489
Found on ASP.NET forum.
Create a handler, download 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 6.0:
Select HTTP Header -> click MIME types - > Click New and add ".msg" as extension and "application/vnd.ms-outlook" as MIME type.
Upvotes: 19
Reputation: 83
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>
Upvotes: 7