title: Loading binary file from db and process it as openxml
body: <p>I have such method to load document file from db that is stored as binary and then replace customxml parts with parameters. </p>
  
  <p>Somehow when i convert byte into MemoryStream then process it doesn't work, my custom xml parts are not replaced. But if i use FileStream and read same file from disk then it replaced perfectly!</p>
  
  <p>What is wrong with MemoryStream? i can't also cast MemoryStream to FileStream or create instrance of Stream or etc.. 
  Any suggestion?</p>
  
  <pre><code>  private static Stream LoadContent(byte[] content, XmlDocument parameters)
      {
          //FileStream works perfectly
          //Stream fileStream = new FileStream(@"C:\temp\test.docx", FileMode.Open);
  
          Stream documentStream = new MemoryStream();
          documentStream.Write(content, 0, content.Length);
  
          //Processes word file, replace custom xml parts with parameters
          using (WordprocessingDocument document = WordprocessingDocument.Open(documentStream, true))
          {
              MainDocumentPart mainPart = document.MainDocumentPart;
              Stream partStream = mainPart.CustomXmlParts.First().GetStream();
  
              using (XmlWriter xmlWriter = XmlWriter.Create(partStream, new XmlWriterSettings { CloseOutput = false }))
              {
                  parameters.WriteTo(xmlWriter);
                  xmlWriter.Flush();
              }
  
              mainPart.Document.Save();
          }
  
          return documentStream;
      }
  </code></pre>