Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 523251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:26:18+00:00 2026-05-13T08:26:18+00:00

My ASP.NET MVC application has pages with attachments and these attachments can be of

  • 0

My ASP.NET MVC application has pages with attachments and these attachments can be of many different file types.

When the user then wants to access their attachment, I need to fire off an FileResult and return the file attachment which I have the path to.

However, I have no database of mime-types, nor do I know off-hand the mime-type of these files off hand.

What is the proper way to handle this? Is there a way I can return a file and let the framework attempt to figure out the mimetype?

Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T08:26:18+00:00Added an answer on May 13, 2026 at 8:26 am

    The way I’ve done it is by keeping a list of well-known extensions and their mime types, and if the extension isn’t found then just return it as application/octet-stream. The reason for this is that this mime type is applied to applications (e.g., exe) which the browser, depending on security settings, may allow you to pass to the operating system, thus opening the default editor for that file type. BTW, consider the security implications for every type of file you may accept and transfer to users.

    Here’s the list I generally use:

      <MimeTypes>
      <MimeType Type="application/mac-binhex40" Extensions=".hqx"/>
      <MimeType Type="application/msword" Extensions=".doc;.docx"/>
      <MimeType Type="application/pdf" Extensions=".pdf"/>
      <MimeType Type="application/postscript" Extensions=".ai;.eps;.ps"/>
      <MimeType Type="application/rtf" Extensions=".rtf"/>
      <MimeType Type="application/vnd.ms-excel" 
                Extensions=".xla;.xlc;.xlm;.xls;.xlt;.xlw;.xlsx"/>
      <MimeType Type="application/vnd.ms-outlook" Extensions=".msg"/>
      <MimeType Type="application/vnd.ms-powerpoint" 
                Extensions=".pot;.pps;.ppt;.pptx"/>
      <MimeType Type="application/vnd.ms-works" Extensions=".wcm;.wdb;.wks;.wps"/>
      <MimeType Type="application/x-compress" Extensions=".z"/>
      <MimeType Type="application/x-compressed" Extensions=".tgz"/>
      <MimeType Type="application/x-gzip" Extensions=".gz"/>
      <MimeType Type="application/x-msaccess" Extensions=".mdb"/>
      <MimeType Type="application/x-msmetafile" Extensions=".wmf"/>
      <MimeType Type="application/x-mspublisher" Extensions=".pub"/>
      <MimeType Type="application/x-msschedule" Extensions=".scd"/>
      <MimeType Type="application/x-msterminal" Extensions=".trm"/>
      <MimeType Type="application/x-mswrite" Extensions=".wri"/>
      <MimeType Type="application/x-tar" Extensions=".tar"/>
      <MimeType Type="application/zip" Extensions=".zip"/>
      <MimeType Type="audio/basic" Extensions=".au;.snd"/>
      <MimeType Type="audio/mid" Extensions=".mid;.rmi"/>
      <MimeType Type="audio/mpeg" Extensions=".mp3"/>
      <MimeType Type="audio/x-aiff" Extensions=".aif;.aifc;.aiff"/>
      <MimeType Type="audio/x-pn-realaudio" Extensions=".ra;.ram"/>
      <MimeType Type="audio/x-wav" Extensions=".wav"/>
      <MimeType Type="image/bmp" Extensions=".bmp"/>
      <MimeType Type="image/gif" Extensions=".gif"/>
      <MimeType Type="image/jpeg" Extensions=".jpe;.jpeg;.jpg"/>
      <MimeType Type="image/pipeg" Extensions=".jfif"/>
      <MimeType Type="image/tiff" Extensions=".tif;.tiff"/>
      <!--Substitute the following two for text/plain if you're sure bad html
      won't get rendered in the browser-->
      <!--<MimeType Type="text/html" Extensions=".mht;.html;.htm"/>-->
      <!--<MimeType Type="text/plain" Extensions=".txt"/>-->
      <MimeType Type="text/plain" Extensions=".txt;.html;.htm"/>
      <MimeType Type="text/richtext" Extensions=".rtx"/>
      <MimeType Type="text/tab-separated-values" Extensions=".tsv"/>
      <MimeType Type="video/mpeg" Extensions=".mp2;.mpa;.mpe;.mpeg;.mpg;.mpv2"/>
      <MimeType Type="video/quicktime" Extensions=".mov;.qt"/>
      <MimeType Type="video/x-la-asf" Extensions=".lsf;.lsx;.asf;.asr;.asx;"/>
      <MimeType Type="video/x-msvideo" Extensions=".avi"/>
      </MimeTypes>
    

    Here’s an example of how to use this (c#-like pseudocode).

    public string GetMimeType(string ext)
    {
      // who would load the file on every method call?  That's just dumb
      var mimes = XElement.Load("MyMimeTypesLolKThx.xml");
      var result = from x in mimes.Elements() 
                   where Contains(x, ext) 
                   select x.Attribute("Type");
      return result.FirstOrDefault() ?? "application/octet-stream";
    }
    
    public bool Contains(XElement el, string ext)
    {
      return el.Attribute("Extensions").Value.Contains(ext);  
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an asp.net mvc application, which has these enity classes: public class
I am developing an ASP.NET MVC application that has two kind of pages: (1)
I have an ASP.NET MVC application that has one part where I dont really
I am creating an ASP.NET MVC application that has postcode lookup functionality. I capture
Other than the fact that ASP.NET MVC Web Application has more clarity in its
I have an ASP.NET MVC 3 application which has a post action called Create
I have an Asp.net MVC application running on AppHarbor. It has the everyday email
We are writing an ASP.NET MVC application. By default, if the client browser has
The company for which I work for has built a large ASP.NET MVC application
I am building a web application using ASP.NET MVC that has two very distinct

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.