Programmatically restore deleted file
One answer
To restore the state, you just need to commit it in a change set. Using IWorkspaceConfiguration#IConfigurationOpFactory#revert will create an op to commit, or you can retrieve the full versionable and save it again using IConfigurationOpFactory#save to get the commit op. Going the save route will result in a new state id being generated.
Comments
Hi Heather,
Hi Scott
If you are using IChangeSetSearchCriteria, not a problem. Once you have picked the change set that has a reference to the version you want restored, retrieve the IChangeSet using IItemManager. IChangeSet#changes() will provide a list of all the versionables changed in the change set. Iterate to find the IChange for your versionable. Get the versionable state handle from IChange#beforeState() IChange#afterState() or IChange#mergeStates() (which you pick depends on which version you are picking).
You can use IConfigurationOpFactory#revert on that handle. The parent folder must still be in the configuration. If thats not the case, then you can retrieve the full versionable (using IVersionableManager), create a working copy, set a different parent and use IConfigurationOpFactory#save.
- Heather
ps. You may want to use the comment link rather than adding new answers to your question.
Hi Heather,
Thanks so much. I was not grabbing the versionableStateHandle. Instead, I was using IChange#item(). Grabbing a state handle has resolved my issue!
Scott
Comments
Scott Pecnik
Sep 10 '12, 5:26 p.m.I've been able to get a versionableHandle by using IConfiguration#determineAncestorsInHistory(), but that only gets me a versionableHandle. If I want to save it to a configuration, I need a versionable. Does anybody know how to grab a versionable of a previously deleted file?
Scott Pecnik
Sep 10 '12, 5:26 p.m.Switching gears a bit, attempting to grab the versionable using IVersionableManager#fetchCompleteState(). The problem is, my IVersionableHandle that I retrieve from determineAncestorsInHistory() does not have a stateID. However, the javadoc for the IAncestorReport#getNameItemPairs() says that "all item handles within the ancestor report carry state ids." I assume that my IVersionableHandle has no stateid because it's been deleted.