title: String of bytes to byte array c#
body: <p>In my web application, I have a connection to a web service. In my Web Service, it has a method for getting the bytes of a report, based on the path:</p>
  
  <pre><code>public byte[] GetDocument(string path)
  {
     byte[] bytes = System.IO.File.ReadAllBytes(path);
     return bytes;
  }
  </code></pre>
  
  <p>Now, when I make a request from my web application, the web service gives me a Json object, similar to this:</p>
  
  <pre><code>{
    "Report":"0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAPgADAP7/CQAGAAAAAAAAAAAA
     AAACAAAA3QAAAAAAAAAAEAAA3wAAAAEAAAD+ ... (continues)" 
  }
  </code></pre>
  
  <p>And in my web application I have a method for fetching the Json object, putting the "report" in a string.
  The web application then has a method for parsing the string of bytes into an array of bytes, which does not work, it throws a <code>FormatException</code>:</p>
  
  <pre><code>public byte[] DownloadReport(string id, string fileName)
  {
      var fileAsString = _api.DownloadReport(id, fileName);
      byte[] report = fileAsString.Split()
                                  .Select(t =&gt; byte.Parse(t, NumberStyles.AllowHexSpecifier))
                                  .ToArray();
      return report;
  }
  </code></pre>
  
  <p>I have also tried to do this:</p>
  
  <pre><code>public byte[] DownloadReport(string id, string fileName)
  {
     var fileAsString = _api.DownloadReport(id, fileName);
     byte[] report = Encoding.ASCII.GetBytes(fileAsString);
     return report;
  }
  </code></pre>
  
  <p>Which gave me a .doc file with the exact same string as the Json object had.</p>
  
  <p>Am I parsing something the wrong way from the web service, or is it when I want to convert it to an array of bytes again?</p>