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