4

I have to implement a functionality of moving a document folder and was hoping to use Folder.MoveTo; But I don't see it in the Microsoft.SharePoint.Client and Microsoft.SharePoint.Client.Runtime for the Folder class.

Note - I am working on SP 2013 Foundation enter image description here

Build Error: Error 2 'Microsoft.SharePoint.Client.Folder' does not contain a definition for 'MoveTo' and no extension method 'MoveTo' accepting a first argument of type 'Microsoft.SharePoint.Client.Folder' could be found (are you missing a using directive or an assembly reference?)

Code:

   private static void FolderMove(ClientContext clientContext, Guid listId, string folderUrl
        , string destinationFolderUrl)
    {
        try
        {
            List list = clientContext.Web.Lists.GetById(listId);
            clientContext.Load(list, w => w.RootFolder.ServerRelativeUrl, w => w.ParentWeb.Url);
            clientContext.ExecuteQuery();

            Folder folder = clientContext.Web.GetFolderByServerRelativeUrl(folderUrl);
            clientContext.Load(folder);
            var destinationFolder = folder.MoveTo(destinationFolderUrl);

            clientContext.Load(destinationFolder);
            clientContext.ExecuteQuery();
        }
        catch (Exception ex)
        {

            throw;
        }
    }
  • 3
    Are you using SP2013 or 2010 . Folder.MoveTo is only available in 2013 version. – Unnie Jul 27 '15 at 11:36
  • Working on SP2013 Foundation – bkk Jul 27 '15 at 11:55
  • Just to troubleshoot check whether , the Microsoft.SharePoint.Client.dll file referenced is from the 15 hive , ie 2013 version and not the 2010 one – Unnie Jul 27 '15 at 12:21
  • Yes I did confirm that, please refer the updated question. – bkk Jul 27 '15 at 12:52
  • Are you getting build error or error while running? – Unnie Jul 27 '15 at 12:56
1

Maybe you have seen this reply already: https://stackoverflow.com/a/26320394/1648371

It's actually saying that there is no MoveTo method for folders, but you have to create a new folder, move all the content, and then delete the old folder. If you are interested in only renaming a folder and not in the content you can use something like

folder.ServerRelativeUrl.Replace(folder.ServerRelativeUrl, newFolderUrl);

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.