Frage

I have one function which uses SearchExecutor finds to find the path of a specified file, which returns a string like.

https://example.sharepoint.com/sites/DevelopementTestingSite/Shared Documents/Forms/DispForm.aspx?ID=43

I have another function which creates and returns a Microsoft.SharePoint.Client.Folder.

Give:

  1. The filename,
  2. The file location, and
  3. The Folder.

How can I copy the file to the folder?

If it helps, the ServerRelativePath has been initialized on the Folder with:

            Folder itemFolder = folderItem.Folder;
            context.Load(itemFolder, folder => folder.ServerRelativePath);
            context.ExecuteQuery();
            return itemFolder;
War es hilfreich?

Lösung

In the string https://example.sharepoint.com/sites/DevelopementTestingSite/Shared Documents/Forms/DispForm.aspx?ID=43, you could get the file by the id. Then copy to the folder.

My test demo code :

        Web web = ctx.Web;
        List list = web.GetListByTitle("Documents");
       // ctx.Load(list);
        //ctx.ExecuteQuery();
        ListItem item = list.GetItemById(2);
        File file = item.File;
        ctx.Load(file);
        ctx.ExecuteQuery();
        item.File.CopyTo("/sites/test/Shared%20Documents/folder1/"+item.File.Name, true);
        ctx.ExecuteQuery();
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit sharepoint.stackexchange
scroll top