Send Sharing Link for Sharepoint Folder

Copper Contributor

I have been battling with this for a few days now... I am using CSCOM to connect to SharePoint. Everything is working fine, creating folders and uploading files. However, I now need to create a shared folder (parent level) link for external users and then initiate the email invite as per the "links giving access" not direct access. I can create and send an anonymous link but this is not what we are after.

string s = "password";
SecureString passWord = new SecureString();
foreach (var c in s)
passWord.AppendChar(c);

string siteURL = "siteurl";
string parentFolder = "parentfolder";


using (Microsoft.SharePoint.Client.ClientContext CContext = new Microsoft.SharePoint.Client.ClientContext(siteURL))
{
CContext.Credentials = new SharePointOnlineCredentials("s-eConnect@nzblood.co.nz",passWord);
var subFolders = CContext.Web.GetFolderByServerRelativeUrl(parentFolder).Folders;
CContext.Load(subFolders);
CContext.ExecuteQuery();

<<create sharing link for parent folder and send email to external user>>>

foreach (var subFolder in subFolders)
{
Console.WriteLine(subFolder.Name.ToString());

}

}
The above code iterates thru the sub folders of the parent, this is me just making sure I am getting the right data. But I can't seem to find anything that allows me to create the sharing link and send to an external user so they get an invite etc...

If I add in the following, it creates an invite but adds the user to the entire site via Direct Access ... not by link to the folder....

var users = new List<UserRoleAssignment>();
users.Add(new UserRoleAssignment()
{
UserId = "rhyndman@altara.net",
Role = Role.View
});

WebSharingManager.UpdateWebSharingInformation(CContext, CContext.Web, users, true, "You've been invited...", true, true);
CContext.ExecuteQuery();

Any help would be appreciated.

Many thanks

0 Replies