Open-XML-SDK
Open-XML-SDK copied to clipboard
`SaveAs` also saves the original.
Description
When I open a document, make changes to some of its elements and later call SaveAs
, the original source file also appears to be overwritten.
This happens even when I set AutoSave
to false and does not happen prior to disposal.
Expected
My initial assumption was that calling SaveAs
would result in the source file never being altered. Similar for example to how a save-as operation in an editor would work. There's some degree of surprise in the current behaviour.
Hmm interesting. Do you have a repro available?
Sorry, no -- very strapped for time at the moment.
Yes, SaveAs
does save the original. Unless deeper architectural changes are made, it must work that way. The main purpose is basically to create a copy, or clone, of the package at the given path, e.g., even if the package was opened on a MemoryStream
.
Assuming you want to keep the original file unchanged, you'd have to read all bytes from that file, copy those to a MemoryStream
, and later save that MemoryStream
using SaveAs
.
Might be worth documenting as the mechanism of Saving As in any other context is to not overwrite the previously-saved path.
@atrauzzi, yes, this would definitely warrant some explicit documentation or even a "warning". @AlfredHellstern, I'd say this is a "feature" and not a "bug". It might also be very complicated to do differently.
Hello, are there any plans for this issue?
As @ThomasBarnekow pointed out, this is how it was designed and would indeed take a much deeper architectural change to alter.
I agree, however, that this API is wrongly named. I'm all for suggestions and we can obsolete this one with a warning and provide an API that is better named.
Thoughts of the top of my head:
-
SaveAndCopyTo(...)
-
SaveAndClone(....)
- CopyTo(....)
Other ideas?
For v3.0, I'm opting to remove the API as-is since it is the same as clone and has unintuitive behavior (#1376). I'd be happy to reconsider a new behavior for this post v3.0 that doesn't have the current downfalls