title: RTF blob to file via SQL Server
body: <p>We are importing a source database X to our target database Y.</p>
  
  <p>X has blobs of text in RTF format which are somehow displayed in its application.</p>
  
  <p>Our web app can't display RTF, so we were instructed to convert those blobs of RTF into files in our database Y.</p>
  
  <p>We simply copy the RTF blob from X, where it is <code>nvarchar</code>, into a column in Y which we already use for storing attachments, which is of type <code>varbinary</code>. Then we write it out as a file <code>foo.rtf</code> when the user wants to view it - so they can download and open the RTF in Word.</p>
  
  <p>Unfortunately the <code>foo.rtf</code> file, when opened in Word, just looks like raw RTF, Something like </p>
  
  <pre><code>{\rtf1\ansi\ansicpg1252\deff0\deftab1134{\fonttbl{....
  </code></pre>
  
  <p>What do we need to do in order to correctly convert this RTF "blob of text" into an actual RTF file? It looks like just saving the bytes doesn't work. </p>
  
  <p>Thank you. </p>