none
TakeOverCheckOut Not working (CSOM 16.1.7521.1200)

    질문

  • I am 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);
                                }

    }

    2018년 6월 12일 화요일 오후 1:25

답변

  • Hi,

    1. As you are using App Only token in the code, then it is expected to display "SharePoint App" in Check Out To field as this is not normal User Credential, it is app only Credential.

    2. TakeOverCheckOut only change the Check Out To field person value not contain file check in action, if you want to check in all the Checked Out files, please use the code below:

     using (var clientContext = new ClientContext("https://xxx.sharepoint.com/sites/xxx"))
                {
                    Web web = clientContext.Web;
                    clientContext.Load(web, a => a.ServerRelativeUrl);
                    clientContext.ExecuteQuery();
                    List list = web.Lists.GetByTitle("doc1");
                    var items = list.GetItems(new CamlQuery(){ViewXml = @"<View Scope='RecursiveAll'><Query><Where><IsNotNull><FieldRef Name='CheckoutUser' /></IsNotNull></Where></Query></View>"});
                    clientContext.Load(items);
                    clientContext.ExecuteQuery();
                    foreach (var item in items)
                    {
                        item.File.CheckIn("1", CheckinType.MajorCheckIn);
                        clientContext.ExecuteQuery();
                    }
                }
    In your original code, CheckedOutFile has no CheckIn method, it is existed in ListItem.File like my demo code above, so get all checkedout files with CAML and then do check in action.

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.


    2018년 6월 13일 수요일 오전 8:02

모든 응답

  • Hi,

    1. As you are using App Only token in the code, then it is expected to display "SharePoint App" in Check Out To field as this is not normal User Credential, it is app only Credential.

    2. TakeOverCheckOut only change the Check Out To field person value not contain file check in action, if you want to check in all the Checked Out files, please use the code below:

     using (var clientContext = new ClientContext("https://xxx.sharepoint.com/sites/xxx"))
                {
                    Web web = clientContext.Web;
                    clientContext.Load(web, a => a.ServerRelativeUrl);
                    clientContext.ExecuteQuery();
                    List list = web.Lists.GetByTitle("doc1");
                    var items = list.GetItems(new CamlQuery(){ViewXml = @"<View Scope='RecursiveAll'><Query><Where><IsNotNull><FieldRef Name='CheckoutUser' /></IsNotNull></Where></Query></View>"});
                    clientContext.Load(items);
                    clientContext.ExecuteQuery();
                    foreach (var item in items)
                    {
                        item.File.CheckIn("1", CheckinType.MajorCheckIn);
                        clientContext.ExecuteQuery();
                    }
                }
    In your original code, CheckedOutFile has no CheckIn method, it is existed in ListItem.File like my demo code above, so get all checkedout files with CAML and then do check in action.

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.


    2018년 6월 13일 수요일 오전 8:02
  • Hi, 

    Thanks for Reply.

    I am having issue of getting "No Checked in version file" files into Normal Flow. ie. file is not moving into Library to do "Check In".

    If am using user credentials instead of "APP Only" token, file is moving into Library for Check-in.

    Please clarify whether TakeOverCheckOut works with only credentials.

    Regards

    Rajkumar V

    2018년 6월 13일 수요일 오후 1:42
  • Hi,

    TakeOverCheckOut is not related to Credential Type, both User/App Only Credential can work with this method if they have enough permission for library.

    The key point to regard is that TakeOverCheckOut not included Check in function, it is necessary to call File.CheckIn like my code demo above.

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    2018년 6월 13일 수요일 오후 1:53
  • Hi,

    Thanks for reply. 


    Issue is because of "CheckedOutFile.ServerRelativePath" property. It has wrong value as "/sites/sitecollection/subsite/sites/sitecollection/subsite/library/folder/file.doc".

    ie. I think the issue was due to ServerRelativePath value Concatenated with List.ParentWebUrl 

    I fixed this issue by using below code to find file to check-in.

    string FileUrl = List.ParentWebUrl.Substring(1) + file.ServerRelativePath.DecodedUrl.Replace(List.ParentWebUrl,"");

    <View><Query><Where><Eq><FieldRef Name='FileRef'/><Value Type='Url'>" + FileUrl  + "</Value></Eq></Where></Query></View>

    Please check and confirm is there any issue in CSOM 16.1.7521.1200 CheckedOutFile.ServerRelativePath


    Thanks & Regards

    Rajkumar V



    • 편집됨 RajKumar_TCS 2018년 6월 14일 목요일 오전 10:29 update
    2018년 6월 14일 목요일 오전 10:20