2014-07-10

Its been a month since I downloaded the latest version of the O365 assemblies and with no suprise O365 assemblies are updated with the new functionality. One of the main thing I found it is ability to mount folder to another folder or to the one drive.

New CSOM api (Microsoft.SharePoint.Client.MountPoint) is available to create and retrieve a mount point.

1. Create a mount point to the target folder in a folder or a One Drive.

Method: MountPoint.CreateMountPoint(ClientRuntimeContext context, Folder folder, string name, Guid targetSiteId, Guid targetWebId, Guid targetUniqueId)

Parameters:
a. Runtime Context
b. Source folder object
c. Mount Name (string)
d. Mount Point Target folder Site Id (GUID)
e. Mount Point Target folder Web Id (GUID)
f. Mount Point Target folder Id (GUID)

if the Source folder is null, it creates the mount point in the One Drive root folder.

The above creates a Shortcut / MountPoint file (as “.url” extension) in the Source folder with the content as

https://***.sharepoint.com/sites/_layouts/16/mountpoint.aspx?site=<<Target folder site ID>>&web=<<Target Folder Web ID>>&item=<<Target Folder ID>>

2. Get the list of mounted folder urls in a list.

Method: MountPoint.GetMountedFolderUrls(ClientRuntimeContext context, List list)

Example:

ClientContext context = new ClientContext("https://****.sharepoint.com/site");
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);
List sourceList = context.Web.Lists.GetByTitle("Source Library");
context.Load(sourceList,sl=>sl.Fields);
Folder sourceListFolder = sourceList.RootFolder.Folders.GetByUrl("source");
context.Load(sourceListFolder,s=>s.UniqueId,s=>s.Files,s=>s.ListItemAllFields);
List targetList = context.Web.Lists.GetByTitle("Target Library");
context.Load(targetList);
Folder targetListFolder = targetList.RootFolder.Folders.GetByUrl("target");
context.Load(targetListFolder,t=>t.UniqueId);
MountPoint.CreateMountPoint(context, sourceListFolder, "hellomount",context.Site.Id, context.Web.Id,targetListFolder.UniqueId);
context.ExecuteQuery();


The above code, creates a mount point for the “target” folder of the “Target Library” in the “Source” folder of the “Source Library”

I think, when we click this MountPoint shortcut, it should redirect the user to the target folder page using the “_layouts/15/MountPoint.aspx” page. For some reason, the redirect is failing which I need to look into it in details.

At the moment, When the user creates a mount using the same name, it appends a number to create a unique name. Also, When the user creates a mount point in a list, it creates the following hidden field in the Source list,

SPMountPointManager.EnsureMetadataField(list, SPFieldType.Boolean.ToString(),”_mpIsFolder”, true);
SPMountPointManager.EnsureMetadataField(list, SPFieldType.Guid.ToString(), “_mpSPSiteId”, false);
SPMountPointManager.EnsureMetadataField(list, SPFieldType.Guid.ToString(), “_mpSPWebId”, false);
SPMountPointManager.EnsureMetadataField(list, SPFieldType.Guid.ToString(), “_mpItemUniqueId”, false);

Note: This feature is not yet published yet. But it gives an idea of the features coming for the O365.

About the author 

Balamurugan Kailasam