Share via

Query About File.MoveTo() functionality in SharePoint 2019 for moving file from One Library to Another Library Programmatically

Prabhakar Kumar 21 Reputation points
2022-06-28T11:48:49.143+00:00

Hello Team,
Hope you are doing well!

I have one doubt about the functionality of a method "public void MoveTo(string newUrl, bool bOverWrite)" in SharePoint 2019 (Program written in C# and created custom solution).

Scenario - We are trying to move the file from one Library to another Library in the same site collection. just wanted to understand the sequence of event occurred behind the scene. As it does create the item first in target library and then delete the file from source Library. Though it worked differently in case of file moving within the library from one folder to other folder as it lifts and shift the file.

Question: is there any chance that this method will delete the file first and create file later? or this can't happened any time?

The reason for asking this is, we wanted to ensure the file movement with highest degree of integrity and we must not miss the file.

Thanks!

Microsoft 365 and Office | SharePoint Server | For business
Microsoft 365 and Office | SharePoint Server | Development

Answer accepted by question author

sadomovalex 3,636 Reputation points
2022-06-29T14:13:57.083+00:00

Sharepoint won't give this guarantee - e.g. if database connection will be dropped during MoveTo call operation may not be fully completed. If you want to ensure that file won't be lost develop logic which will make copy of the file to some storage before to move it.

Was this answer helpful?

0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Prabhakar Kumar 21 Reputation points
    2022-07-04T02:25:32.39+00:00

    Thank you All. I got the answer. We can close this thread now.
    Regards,
    Prabhakar

    Was this answer helpful?

    0 comments No comments

  2. Tong Zhang_MSFT 9,261 Reputation points
    2022-06-29T08:51:29.18+00:00

    Hi @Prabhakar Kumar ,

    According to my research and testing, unfortunately, there is no official documentation describe the workflow of the File.MoveTo() method, so it is not possible to determine whether it is possible to delete a file first and then create it later. As a workaround, you could make a backup of the file before moving it, and then use the File.MoveTo() method.

    Hope it can help you. Thanks for your understanding.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.