Binary Data vs Character Data confusion
<p>Ok, so I have a function that takes the path to an image file and is supposed to return the binary data as a string. The caller then inserts the returned string into the inner text of an XML element. </p>

<p>Is this correct?:</p>

<pre><code>string dataAsString = "";
using (StreamReader sr = new StreamReader(new FileStream(mergedFile, FileMode.Open, FileAccess.Read, FileShare.Read, 2048, FileOptions.DeleteOnClose)))   
dataAsString = sr.ReadToEnd();  
return dataAsString;
</code></pre>

<p>This returns something that looks like it might legitimately be binary data but if I cut and paste the contents out of the target file, paste it into a new test tif file and then attempt to open the tif image, it is unhappy with me... so I suspect something is wrong with the way I'm reading/writing the data.</p>

<p>Must I really do something like this?</p>

<pre><code>using (BinaryReader br = new BinaryReader(new FileStream(mergedFile, FileMode.Open, FileAccess.Read, FileShare.Read, 1024, FileOptions.None)))   
{
  int blockReadSz = 2048;
  int bytesToRead = (int)br.BaseStream.Length;
  int bytesRead = 0;
  byte[] data = new byte[bytesToRead];
  while (bytesRead &lt; bytesToRead)      
    bytesRead += br.Read(data, bytesRead, blockReadSz);    
}
</code></pre>

<p>And if so, how do I get a string out of the byte[] once I'm done reading the file in? </p>

<p>Thanks for any help! :D</p>
