/// <summary>
/// Gets the name of the previous file's state.
/// </summary>
/// <param name="file">File</param>
/// <returns></returns>
/// <exception cref="System.ArgumentNullException">File is null.</exception>
/// <exception cref="System.Runtime.InteropServices.COMException">
/// File has state changes history.
/// or
/// File has no history.
/// </exception>
public static string GetPreviousState(this IEdmFile5 file)
{
var stateName = string.Empty;
if (file == null)
throw new ArgumentNullException("file");
var vault = file.Vault as IEdmVault7;
var history = vault.CreateUtility(EdmUtility.EdmUtil_History) as IEdmHistory;
EdmHistoryItem[] historyitems = null;
history.AddFile(file.ID);
history.GetHistory(ref historyitems, (int)EdmHistoryType.Edmhist_FileState);
if (history == null)
throw new COMException("File has state changes history");
if (historyitems.Length == 0)
throw new COMException("File has no history.");
stateName = historyitems[0].moData.mbsStrData1;
var workflow = vault.GetObject(EdmObjectType.EdmObject_Workflow, (file.CurrentState as IEdmState6).WorkflowID) as IEdmWorkflow6;
return stateName.Replace(workflow.Name,"").Trim();
}
3 Likes