I was implementing a functionality that inserts document content using Spire.Doc and encountered a bug when creating the output file.
I've also reproduced the issue using a blank document and the code below:
- Code: Select all
string sourcePath = //Insert path of blank document here
byte[] fileByteArr = System.IO.File.ReadAllBytes(sourcePath);
using (MemoryStream mem = new MemoryStream())
{
mem.Write(fileByteArr, 0, fileByteArr.Length);
Spire.Doc.Document doc = new Spire.Doc.Document(mem, FileFormat.Docx);
mem.Position = 0;
doc.SaveToStream(mem, FileFormat.Docx);
string path = @"D:\res.docx";
using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write))
{
mem.WriteTo(fs);
}
}
When the created word doc is opened, an "unreadable content" error is displayed. (screenshot attached)
Spire.Doc v11.5.6
.Net Framework 4.7.2
Visual Studio Community 2019 running on Win10