2

我对使用客户端对象模型以编程方式添加到 Sharepoint 2013 组的用户的用户权限存在问题。Web 应用程序允许匿名,但我也有一个文档库“Teacher Documents”,仅对某个组(比如说“Teachers”)有贡献权限,并且我也将用户添加到该站点的默认成员中(比如说“School成员”)。该代码工作正常,用户已成功添加到两个组中。

虽然看起来确实不错,并且用户名被列为组的成员,但他们仍然无法贡献。当我检查时,他们确实对文档库具有匿名访问权限,但没有贡献权限。这是我的代码:

public static string AddUserToGroup(string siteURL, string groupName, string userName, string name, string email, NetworkCredential impersonateCredential)
{
    try
    {
        ClientContext context = new ClientContext(siteURL);
        context.Credentials = impersonateCredential;

        Group oGroup = null;

        oGroup = context.Web.SiteGroups.GetByName(groupName);

        context.Load(oGroup);
        bool groupExists = false;

        try
        {
            context.ExecuteQuery();
            groupExists = true;
        }
        catch { }

        if (groupExists)
        {
            UserCreationInformation userCreationInfo = new UserCreationInformation();
            userCreationInfo.Email = email;
            userCreationInfo.LoginName = userName;
            userCreationInfo.Title = name;

            bool userExists = false;

            try
            {
                User checkUser = oGroup.Users.GetByLoginName(userName);
                context.Load(checkUser);
                context.ExecuteQuery();
                userExists = true;
            }
            catch { }

            if (!userExists)
            {
                User oUser = oGroup.Users.Add(userCreationInfo);
                context.ExecuteQuery();
            }
        }
        else
        {
            return "No associated group assigned";
        }

        return "Member " + userName + " has been added to group.";
    }
    catch (Exception ex)
    {
        return ex.Message.ToString();
    }
}

这就是我所说的:

string siteURL = "http://spfe01.gilang.com/";
string username = "spfe01\\budi.utomo";
string name = "Budi Utomo";
string email = "budi.utomo@spfe01.gilang.com";

NetworkCredential impersonateCredential = new NetworkCredential("username", "password", "spfe01");

AddUserToGroup(siteURL, "Teachers", username, name, email, impersonateCredential));

(您可以在控制台应用程序上对其进行测试)

它有效,用户被添加到“教师”,但没有“教师文档”文档库的权限。将用户添加到对站点具有完全控制权的管理组“学校所有者”也不起作用。

编辑: 就我而言,我已手动将组添加到文档库,手动添加到组的用户被授予权限并允许参与。手动是指在 Web 浏览器上使用 Sharepoint 的标准“权限”功能。

4

1 回答 1

0

其实,你有没有打破传承?

很可能,文件夹和文件继承了主文件夹的权限

这是我的代码:

caml = new Microsoft.SharePoint.Client.CamlQuery();

caml.ViewXml = @"Caml to get the file";

items = objList.GetItems(caml);

clientContext.Load(items);

clientContext.Credentials = new NetworkCredential("LoginID", "LoginPW", "LoginDomain");

clientContext.ExecuteQuery();

item = items[0];

item.BreakRoleInheritance(true, true);

clientContext.ExecuteQuery();
于 2014-06-27T05:57:59.067 回答