I have a document approval system that works something like this:
- User uploads a document to one library, fills out metadata.
- Approval process begins, workflows are fired to send out notification emails, the document might be edited, but the metadata is not likely to change.
- Upon final approval, an event receiver fires and uses
SPFile.MoveTo()
to move the document to another library.
Now I'm seeing some odd behavior with the version history after the file is moved. The versions appear to be there, but when you go to look at the version history:
- The version where all the metadata is set has changed from the first version (when the file was uploaded) to the most recent version. Odd, but I don't care too much about that.
- For every version the
Modified By
user has changed to be the user that gave the final approval and triggered the event receiver!
That would seem like maybe a bug to me? That kind of invalidates the version history, because you can't then see who was responsible for which version.
Is there any way to move a file, in code, preserving version history including the modified by user for each version?
I would prefer not to have to bend over backwards to do something obtuse like:
- Before moving the document, loop through the versions and collect the
Modified By
users. - Move the document using
SPFile.MoveTo()
. - Reach into the document in its new location, and loop through the versions, and reset the
Modifed By
users back to the originals, and then doSystemUpdate()
or something to make the changes stick. I mean... I don't even know if something like that is possible.