title: byte[] to File Type in MVC 3
body: <p>In my MVC application, I recently have configured a page to allow an arbitrary file type to be uploaded(with certain restrictions that dont apply to this question).</p>
  
  <p>I am storing the file as data type byte[] in the database, with the stored file type based off of the file extension(Please dont try to give me a better option for storing these files, I am well aware that storing files in the database is not a good practice, but we have a constraint that requires that we persist these files using SQL Server.)</p>
  
  <p>As I was saying, to make this even worse, I am storing the byte[] array of the file in a column in the database which is of type <strong>text</strong>. This is only done so I dont have to worry about restrictions with the varbinary type.</p>
  
  <p>What I want to know is, when a file is requested, what is the best way <strong>in MVC</strong> to return these files to the user with a specified file extension?</p>
  
  <p>I have been able to do this before with excel files and an AJAX call to a "GET" action on my controller, but I want to know if there is a better way to do it.</p>
  
  <p>Any suggestions?</p>
  
  <p>Example: If I have the following code</p>
  
  <pre><code>string fileExtension = /*Some File Extension*/
  byte[] data = MyDataContext.DocumentTable.First(p =&gt; p.DocumentUID == id);
  </code></pre>
  
  <p>How can I then return this <strong>data</strong> to the user in the specified file format using the <strong>fileExtension</strong> that was originally persisted.</p>
  
  <p><b>EDIT</b> I am guessing that <strong>FileResult</strong> will be one of the easiest ways to accomplish this.</p>