0

hi im using method for copy or move file on sharepoint. but i want to ask how to implement when it's duplicated it automatically replace and update version?

i've been try with this function but it's always

Microsoft.SharePoint.Client.ServerException: 'The destination file already exists

public void CopyFile(string SrcUrl, string DestUrl)
    {
        MoveCopyOptions option = new MoveCopyOptions();
        option.KeepBoth = false;
        MoveCopyUtil.CopyFile(this.clientContext,SrcUrl,DestUrl,true,option);
        this.clientContext.ExecuteQuery();
    }

And my src

http://win-e636ggi1v13:55555/sites/srsrms/SRS%20Documents/Finance/fredytest/License%20Management.csv

and my Destination file

http://win-e636ggi1v13:55555/sites/srsrms/SRS%20Documents/Finance/paidi/Finance%20Folder/License%20Management.csv
0

You can create a object of MoveCopyOptions that has boolean property KeepBoth. To handle similar file names you can set MoveCopyOptions. If you want to preserve both file after copying/moving set MoveCopyOptions.KeepBoth to true, else make it false.

4
  • hi i've been change this but doesn't work did im wrong ,i've been set to true for overwrite MoveCopyOptions option = new MoveCopyOptions(); option.KeepBoth = true; MoveCopyUtil.CopyFile(this.clientContext,SrcUrl,DestUrl,true,option); this.clientContext.ExecuteQuery(); Sep 8 '20 at 1:40
  • hi @Akshay Randive i've been update why still error. Sep 8 '20 at 7:10
  • I am not sure why this is not working. Can you try setting Overwite false and KeepBoth false Sep 8 '20 at 10:58
  • yes sir i've been try setting overwrite false and keepboot false.but doesn't work this function. im using sharepoint 2016 is that work with latest CSOM? Sep 8 '20 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.