2014-09-02

It seems like the new O365 Client library has got some more features now and one of the commonly used Copy / Move the files or folders functionality from a library to a new destination is available now.

A new utility class Microsoft.SharePoint.Client.MoveCopyUtil is available on the latest version of the O365 Microsoft.SharePoint.Client.dll

Microsoft.SharePoint.Client.MoveCopyUtil has the following functions:

  • public static void MoveFile(ClientRuntimeContext context, string srcUrl, string destUrl)
  • public static void CopyFile(ClientRuntimeContext context, string srcUrl, string destUrl)
  • public static void MoveFolder(ClientRuntimeContext context, string srcUrl, string destUrl)
  • public static void CopyFolder(ClientRuntimeContext context, string srcUrl, string destUrl)

I just tried the above method for the DocumentSet / Files and it seems to be Copying / Moving the objects with the metadata and also fires the Remote event receivers.

Example:

ClientContext context = new ClientContext("https://****.sharepoint.com/sites/*/*");
string password = "***";
var secure = new SecureString();
foreach (var c in password.ToCharArray()) secure.AppendChar(c);
 
context.Credentials = new SharePointOnlineCredentials("*@*.onmicrosoft.com", secure);
context.Load(context.Web, w => w.Title, w => w.Id);
context.Load(context.Site, s => s.Id);
                       
ClientAction query = new ClientActionInvokeStaticMethod(context, "{c668c5ca-bbdd-435f-8008-502f3180cf20}", "CopyFolder", new object[]
{
"https://***.sharepoint.com/sites/*/**/*/*/<<lib>>/PWR1_2", // PWR1_2 => Source DocumentSet
"https://****.sharepoint.com/sites/*/*/*/*/<<lib>>/PWR1_2_Copied"// PWR1_2_Copied => Copied DocumentSet
});
context.AddQuery(query); 
 
context.ExecuteQuery();

The above script copies the PWR1_2 DocumentSet in the same library as PWR1_2_Copied with all the metadata and files within it.

Note: This feature is not yet published yet. 

About the author 

Balamurugan Kailasam