title: How to make content type MIME type dynamic in mvc?
body: <p>I am using following code to list a file from a folder and display for download </p>
  
  <pre><code>public FileResult Download(string id)
      {
          int fid = Convert.ToInt32(id);
          var files = new DataClasses().GetFiles();
          string filename = (from f in files
                             where f.FileId == fid
                             select f.FilePath).First();
          string contentType = "application/doc";
          //Parameters to file are
          //1. The File Path on the File Server
          //2. The content type MIME type
          //3. The parameter for the file save by the browser
          return File(filename, contentType, "Report.doc");
      }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/BGN8V.png" alt="enter image description here">
  here everything is working fine for word documents  but if I place any other type of file like excel or pdf it showing error I know this error is due to  <strong><em>contentType = "application/doc";</em></strong>
  I want to ask how to make the content type dynamic so that any kind of file inside the folder can be easily downloaded.</p>
  
  <p>I know I can do it something like</p>
  
  <pre><code>string contentType = string.Empty;    
          if (CurrentFileName.Contains(".pdf"))  
          {  
              contentType = "application/pdf";  
          }    
          else if (CurrentFileName.Contains(".docx"))  
          {  
              contentType = "application/docx";  
          }  
  </code></pre>
  
  <p>But here I need to write condition for every file type. Is there any way to ignore these condition checks?   </p>