-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Description
In the process of porting some .NET Framework code that reads OOXML (specifically Word format) files to .NET Core I have hit a rough patch because the API PackagePage.GetStream() is returning a forward-only Stream (CanSeek is false). The code relies on the stream being random access since the .NET Framework API returns such a stream. I think this is related to #1550 but in the opposite way since that is talking about having a forward only API. So is the .NET Core API as designed not compatible with .NET Fx and the only way out is to wrap the forward-only stream with a memory buffer?
Here is code which demonstrates this:
string file = @"C:\Temp\DocStudio\simple.docx";
using (var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read))
using (var package = Package.Open(fileStream, FileMode.Open, FileAccess.Read))
{
if (Uri.TryCreate("/word/document.xml", UriKind.Relative, out Uri docUri) && package.PartExists(docUri))
{
var documentPart = package.GetPart(docUri);
using (var stream = documentPart.GetStream())
{
var canSeek = stream.CanSeek;
Console.WriteLine("stream canSeek: " + canSeek);
}
}
}