title: How to Convert BinaryData to File in C#?
body: <p>Actually I have saved some files like .<code>pdf</code>,.<code>txt</code>,.<code>doc</code>,.<code>xls</code> by converting them to <code>&lt;Binary data&gt;</code> in my <code>SQL SERVER DB</code> through <code>FileUploadControl</code>.
  Now, I want to Convert the <code>&lt;Binary data&gt;</code> back to Normal and give an option for user to Download (or) View that data.</p>
  
  <p>I have tried some thing like this for the .<code>txt</code> files </p>
  
  <pre><code>var filedata = (from xx in VDC.SURVEY_QUESTION_REPLIES
                                      where xx.ID == FileID
                                      select xx).FirstOrDefault();
  
  string fileextension = filedata.FILE_EXTENSION.ToString();
  string fileName = filedata.ANSWER_TEXT.ToString() + fileextension;
  Byte[] bytes = (Byte[])filedata.FILE_DATA;
  Response.Buffer = true;
  Response.Charset = "";
  Response.Cache.SetCacheability(HttpCacheability.NoCache);
  Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
  Response.BinaryWrite(bytes);
  Response.Flush();
  Response.End();
  </code></pre>
  
  <p>I am getting an error like : </p>
  
  <blockquote>
    <p><em>Unable to evaluate expression because the code is optimized or a
    native frame is on top of the call stack.</em></p>
  </blockquote>