Send Sharing Link for Sharepoint Folder

%3CLINGO-SUB%20id%3D%22lingo-sub-2187695%22%20slang%3D%22en-US%22%3ESend%20Sharing%20Link%20for%20Sharepoint%20Folder%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2187695%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20been%20battling%20with%20this%20for%20a%20few%20days%20now...%20I%20am%20using%20CSCOM%20to%20connect%20to%20SharePoint.%20Everything%20is%20working%20fine%2C%20creating%20folders%20and%20uploading%20files.%20However%2C%20I%20now%20need%20to%20create%20a%20shared%20folder%20(parent%20level)%20link%20for%20external%20users%20and%20then%20initiate%20the%20email%20invite%20as%20per%20the%20%22links%20giving%20access%22%20not%20direct%20access%3CA%20href%3D%22https%3A%2F%2Fdjcontrollerhub.com%2F%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E.%3C%2FA%3E%20I%20can%20create%20and%20send%20an%20anonymous%20link%20but%20this%20is%20not%20what%20we%20are%20after.%3C%2FP%3E%3CP%3Estring%20s%20%3D%20%22password%22%3B%3CBR%20%2F%3ESecureString%20passWord%20%3D%20new%20SecureString()%3B%3CBR%20%2F%3Eforeach%20(var%20c%20in%20s)%3CBR%20%2F%3EpassWord.AppendChar(c)%3B%3C%2FP%3E%3CP%3Estring%20siteURL%20%3D%20%22siteurl%22%3B%3CBR%20%2F%3Estring%20parentFolder%20%3D%20%22parentfolder%22%3B%3C%2FP%3E%3CP%3E%3CBR%20%2F%3Eusing%20(Microsoft.SharePoint.Client.ClientContext%20CContext%20%3D%20new%20Microsoft.SharePoint.Client.ClientContext(siteURL))%3CBR%20%2F%3E%7B%3CBR%20%2F%3ECContext.Credentials%20%3D%20new%20SharePointOnlineCredentials(%22s-eConnect%40nzblood.co.nz%22%2CpassWord)%3B%3CBR%20%2F%3Evar%20subFolders%20%3D%20CContext.Web.GetFolderByServerRelativeUrl(parentFolder).Folders%3B%3CBR%20%2F%3ECContext.Load(subFolders)%3B%3CBR%20%2F%3ECContext.ExecuteQuery()%3B%3C%2FP%3E%3CP%3E%26lt%3B%3CCREATE%20sharing%3D%22%22%20link%3D%22%22%20for%3D%22%22%20parent%3D%22%22%20folder%3D%22%22%20and%3D%22%22%20send%3D%22%22%20email%3D%22%22%20to%3D%22%22%20external%3D%22%22%20user%3D%22%22%3E%26gt%3B%26gt%3B%3C%2FCREATE%3E%3C%2FP%3E%3CP%3Eforeach%20(var%20subFolder%20in%20subFolders)%3CBR%20%2F%3E%7B%3CBR%20%2F%3EConsole.WriteLine(subFolder.Name.ToString())%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%7D%3C%2FP%3E%3CP%3E%7D%3CBR%20%2F%3EThe%20above%20code%20iterates%20thru%20the%20sub%20folders%20of%20the%20parent%2C%20this%20is%20me%20just%20making%20sure%20I%20am%20getting%20the%20right%20data.%20But%20I%20can't%20seem%20to%20find%20anything%20that%20allows%20me%20to%20create%20the%20sharing%20link%20and%20send%20to%20an%20external%20user%20so%20they%20get%20an%20invite%20etc...%3C%2FP%3E%3CP%3EIf%20I%20add%20in%20the%20following%2C%20it%20creates%20an%20invite%20but%20adds%20the%20user%20to%20the%20entire%20site%20via%20Direct%20Access%20...%20not%20by%20link%20to%20the%20folder....%3C%2FP%3E%3CP%3Evar%20users%20%3D%20new%20List%3CUSERROLEASSIGNMENT%3E()%3B%3CBR%20%2F%3Eusers.Add(new%20UserRoleAssignment()%3CBR%20%2F%3E%7B%3CBR%20%2F%3EUserId%20%3D%20%22rhyndman%40altara.net%22%2C%3CBR%20%2F%3ERole%20%3D%20Role.View%3CBR%20%2F%3E%7D)%3B%3C%2FUSERROLEASSIGNMENT%3E%3C%2FP%3E%3CP%3EWebSharingManager.UpdateWebSharingInformation(CContext%2C%20CContext.Web%2C%20users%2C%20true%2C%20%22You've%20been%20invited...%22%2C%20true%2C%20true)%3B%3CBR%20%2F%3ECContext.ExecuteQuery()%3B%3C%2FP%3E%3CP%3EAny%20help%20would%20be%20appreciated.%3C%2FP%3E%3CP%3EMany%20thanks%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2187695%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Occasional 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