title: Storing an SVG as bytes in DB?
body: <p>Wee bit of background to set the scene : we've told a client he can provide us with images of any type and we'll put them on his reports. I've just had a quick run through of doing this and found that the reports (and other things between me and them) are all designed to only use SVGs.</p>
  
  <p>I thought I'd struck gold when I found online that you can convert an image from a jpg or PNG into an SVG using free tools but alas I've not yet succeeded in getting an SVG stored as bytes in the DB in a format that allows me to use it again after reading it back out.</p>
  
  <p>Here's a quick timeline of what followed leading up to my problem.</p>
  
  <ol>
  <li>I use an online tool to generate an SVG from a PNG (e.g., MobileFish)</li>
  <li>I can open and view it in Firefox and it looks ok</li>
  <li>I ultimately need the SVG to be stored as bytes in the DB, from where the report will pull it via a webpage that serves it up as SVG. So I write it as bytes into a SQL data script. The code I use to write these bytes is included below.</li>
  <li>I visit said webpage and I get an error that there is an "XML parsing error on Line 1 Column 1" and it shows some of my bytes. They begin "3C73"</li>
  <li>I revisit the DB and compare the bytes I've just written there with some pre-existing (and working ones). While my new ones begin "3C73", the others begin "0xFFFE".</li>
  </ol>
  
  <p>I think I've probably just pointed out something really fundamental but it hasn't clicked.</p>
  
  <p>Can someone tell me what I've done that means my bytes aren't stored in the correct encoding/format?</p>
  
  <p>When I open my new SVG in Notepad++ I can see the content includes the following which could be relevant :</p>
  
  <pre><code>&lt;image width="900" height="401" xLink:href="data:image/png;base64,
  </code></pre>
  
  <p>(base 64 encoded data follows for 600+ lines)    </p>
  
  <p>Here's the brains of the code that turns my SVG into the bytes to be stored in DB :</p>
  
  <pre><code>var bytes = File.ReadAllBytes(file);
  using (var fs = new StreamWriter(file + ".txt"))
  {
      foreach (var item in bytes)
      {
          fs.Write(String.Format("{0:X2}",item));
      }
  }
  </code></pre>
  
  <p>Any help appreciated.</p>
  
  <p>Cheers</p>