title: VB.Net printing xps file "File contains corrupted data" error
body: <p>I have an xps file.  When I try to print this file directly, I can do it without any error with my below code:</p>
  
  <pre><code>Dim defaultPrintQueue = LocalPrintServer.GetDefaultPrintQueue
  
  Dim xpsPrintJob As PrintSystemJobInfo = defaultPrintQueue.AddJob("test", "C:\Temp\test.xps", False)
  </code></pre>
  
  <p>However, If I get this file from a web service as a byte array and save it as an xps file I cannot print it.</p>
  
  <p>My save byte array codes are below:</p>
  
  <pre><code>FS = New IO.FileStream("C:\Temp\test.xps", FileMode.Create)
                          FS.Write(arrayByte, 0, arrayByte.Length)
                          FS.Close()
  </code></pre>
  
  <p>or this code:</p>
  
  <pre><code> File.WriteAllBytes("c:\Temp\test.xps", arrayByte)
  </code></pre>
  
  <p>When I try to print test.xps, I'm getting the error:</p>
  
  <blockquote>
    <p>An unhandled exception of type 'System.Printing.PrintJobException'
    occurred in System.Printing.dll</p>
    
    <p>Additional information: An exception occurred while creating print job
    information. Check inner exception for details.</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/sb57X.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sb57X.png" alt="Detailed view of the error is here"></a></p>
  
  <p>Have can I handle this problem? Is anyone has any idea?</p>
  
  <hr>
  
  <p>By the way, there is no need a web service.
  Please see my below code. 
  You can try this any xps file.
  Firstly, I'm assinging the file as byte array
  Then, I'm saving the byte array as an xps file.</p>
  
  <p>First XPS file is working but second one isn't working </p>
  
  <pre><code>Dim FS As FileStream
  FS = File.Open("C:\Temp\test2.xps", FileMode.Open, FileAccess.Read)
  
  Dim bByte(FS.Length) As Byte
  FS.Read(bByte, 0, FS.Length)
  FS.Close()
  
  File.WriteAllBytes("c:\Temp\test2byte.xps", bByte)
  
  Dim defaultPrintQueue = LocalPrintServer.GetDefaultPrintQueue
  
  'This is working
  Dim xpsPrintJob1 As PrintSystemJobInfo = defaultPrintQueue.AddJob("Test", "C:\Temp\test2.xps", False)
  
  'This is not working
  Dim xpsPrintJob2 As PrintSystemJobInfo = defaultPrintQueue.AddJob("Test", "C:\Temp\test2byte.xps", False)
  </code></pre>