Featured Post

SQL Query in SharePoint

The "FullTextSqlQuery" object's constructor requires an object that has context but don't be fooled. This context will no...

Wednesday, January 9, 2013

How to copy one PackagePart to another

One of the most used functions in my xml utilities class is the one that copies the contents from one PackagePart to another. It's simple but if you don't know how here's a easy code snippet :)

public static void CopyContents(PackagePart packagePartIn, PackagePart packagePartOut){

  using (Stream outputStream = packagePartOut.GetStream(FileMode.Create, FileAccess.Write))  {

    using (Stream stream = packagePartIn.GetStream())    {

      byte[] contents = new byte[stream.Length];      stream.Read(contents, 0, contents.Length);
      outputStream.Write(contents, 0, contents.Length);
    }
  }
}

No comments:

Post a Comment