1

In my project, I have to clone some specific file and rename it with adding a prefix "Copy-".

For example:

original:  itemA, itemB, itemC
Now:       itemA, itemB, itemC, Copy-itemA

So, I tried the following code to move the file between the same library and folder.

  SPFile cloneFile= doc.File;
  moveFile.MoveTo(Path.Combine(originalItem.Url, "Copy" + fileName ));

It fails! It just replaces my original file with the name "Copy-XXXX" :(

original:  itemA, itemB, itemC
Now:       Copy-itemA, itemB, itemC, 

any idea ?

3

Use File.CopyTo instead of File.MoveTo as MoveTo function removes the existing file and creates the new one whereas the CopyTo function will give you a copy of a file . then you can update the metadata of the file.

  • What column(s) will be changed in file.copyTo? Name, id, Modified,Modified By.. anymore? – king yau Nov 17 '16 at 10:27
  • 1
    the file will be copied to the location specified and yes , the default fields CreatedBy , ModifedBy , Created , Modified will be updated to the current values . and other custom metadata fields can be updated as per our requirements – Esaki Nov 17 '16 at 10:30
  • greeting, do you have any idea to get the ID of the clone item? – king yau Nov 18 '16 at 2:34

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.