EvotecIT / OfficeIMO

Fast and easy to use cross-platform .NET library that creates or modifies Microsoft Word (DocX) and later also Excel (XLSX) files without installing any software. Library is based on Open XML SDK
MIT License
280 stars 50 forks source link

Stream does not support writing. #65

Closed PrzemyslawKlys closed 1 year ago

PrzemyslawKlys commented 1 year ago

@rstm-sf it seems your change for Save has broken some examples

System.NotSupportedException
  HResult=0x80131515
  Message=Stream does not support writing.
  Source=System.Private.CoreLib
  StackTrace:
   at System.ThrowHelper.ThrowNotSupportedException_UnwritableStream()
   at System.IO.FileStream.SetLength(Int64 value)
   at OfficeIMO.Word.WordDocument.Save(String filePath, Boolean openWord) in C:\Support\GitHub\OfficeIMO\OfficeIMO.Word\WordDocument.cs:line 602
   at OfficeIMO.Word.WordDocument.Save(Boolean openWord) in C:\Support\GitHub\OfficeIMO\OfficeIMO.Word\WordDocument.cs:line 633
   at OfficeIMO.Examples.Word.LoadDocuments.LoadWordDocument_Sample1(Boolean openWord) in C:\Support\GitHub\OfficeIMO\OfficeIMO.Examples\Word\LoadDocuments\LoadDocuments.Sample1.cs:line 30
   at OfficeIMO.Examples.Program.Main(String[] args) in C:\Support\GitHub\OfficeIMO\OfficeIMO.Examples\Program.cs:line 76

image

All examples that load documents seem to be affected:

LoadDocuments.LoadWordDocument_Sample1(false);
LoadDocuments.LoadWordDocument_Sample2(false);
LoadDocuments.LoadWordDocument_Sample3(false);
PrzemyslawKlys commented 1 year ago

Never mind, the documents were set to read only and that's why it was throwing an error. Maybe it should be handled more gracefully with added proper error.