CharlieDigital

Greetings All,

For a document which is checked out from a SharePoint workspace, is it possible to programmatically discard the document checkout from an add-in

The most reasonable API call would seem to be:

Word.ActiveDocument.CheckIn(false, ref comments, false)

But I have been unsuccessful with this call, which raises the error:

System.Runtime.InteropServices.COMException was unhandled
HelpLink="C:\\Program Files\\Microsoft Office\\Office12\\1033\\WDMAIN11.CHM#25573"
Message="The check out cannot be undone."
Source="Microsoft Word"
ErrorCode=-2146822195
StackTrace:
at Microsoft.Office.Interop.Word.DocumentClass.CheckIn(Boolean SaveChanges, Object& Comments, Boolean MakePublic)

While the message in the exception claims "The check out cannot be undone", from the Word UI, it is indeed possible to discard the check out, so the error is a bit misleading. Is there an API call to discard the check-in that I simply haven't found Or perhaps I'm doing something incorrectly with the call to CheckIn

Any leads would be appreciated.

Thanks.




Re: Visual Studio Tools for Office Possible to Programmatically Discard Checkout?

MSDNuser181

Ive done something like that from the object model (you must run on the SharePoint server, may be called from a WebService). This is a code fragment:

SPQuery Q = new SPQuery();
Q.Query = . . . // CAML
SPListItemCollection ItemPrincipal = MainLista.GetItems(Q);
foreach (SPListItem Item in ItemPrincipal)
{

if (Item.File.CheckOutStatus == SPFile.SPCheckOutStatus.LongTerm ||
Item.File.CheckOutStatus == SPFile.SPCheckOutStatus.LongTermOffline)
{
Item.File.UndoCheckOut();
}
Item.Update();
}

}


There might be something available at the WebService SharePoint API.