简体   繁体   中英

How i can programmatically share some file in Sharepoint 2013 when i'm not an administrator?

I have edit permission to some file in sharepoint 2013 and i want to share this file with someone. I use this code:

var item = rootList.GetItemById(itemId);
clientContext.Load(item);
clientContext.ExecuteQuery();

var allRoles = GetAllRoleDefinitions(clientContext);
var roleToAssign = allRoles.FirstOrDefault(r => r.Name == "Contribute");
var principal = clientContext.Web.SiteUsers.GetById(member.Id);
var roleAssignmentForUser = item.RoleAssignments.GetByPrincipalId(member.Id);
roleAssignmentForUser.RoleDefinitionBindings.Add(roleToAssign);
clientContext.ExecuteQuery();

But it throws ServerUnauthorizedAccessException. I checked this in sharepoint site and this is possible.

Try running this Powershell script. It will remove anonymous access restrictions. It might help even though your users are authenticated.

$webApp = Get-SPWebApplication -Identity http://[your sharepoint url] $webApp.ClientCallableSettings.AnonymousRestrictedTypes.Remove([Microsoft.SharePoint.SPList], "GetItems") $webApp.Update()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM