Forum Discussion
Microsoft.SharePoint.Client.CheckedOutFile - TakeOverCheckOut Not working (CSOM 16.1.7521.1200)
I trying to "Take Ownership" of the files which are in "No checked in version" by using latest CSOM version 16.1.7521.1200 from SharePoint Online.
I am using App Only token to do execute this method. It didn't throw any exception but changes "Checkoutby" user to "SharePoint App" and file remains in same state (No Checked in version)
Please help me to resolve this.
Code:
string siteurl ="https://<site>.sharepoint.com"
Uri siteUri = new Uri(siteurl);
string realm = TokenHelper.GetRealmFromTargetUrl(siteUri);
string token = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, siteUri.Authority, realm).AccessToken;
clientContext = TokenHelper.GetClientContextWithAccessToken(siteUri.ToString(), token);
List list = web.GetListByTitle("LibraryName");
checkedOutFiles = list.GetCheckedOutFiles();
clientContext.Load(checkedOutFiles);
clientContext.ExecuteQueryRetry();
foreach (var file in checkedOutFiles)
{
try {
Console.WriteLine("Getting Checked out file " + file.ServerRelativePath.DecodedUrl);
file.TakeOverCheckOut();
clientContext.ExecuteQueryRetry();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}