Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 如何以编程方式授予';阅读';对sharepoint中特定列表的组/用户的权限_Asp.net_Sharepoint_Permissions - Fatal编程技术网

Asp.net 如何以编程方式授予';阅读';对sharepoint中特定列表的组/用户的权限

Asp.net 如何以编程方式授予';阅读';对sharepoint中特定列表的组/用户的权限,asp.net,sharepoint,permissions,Asp.net,Sharepoint,Permissions,如何以编程方式向组/用户授予特定列表的“读取”权限? 我已在共享点中手动创建了一个组。 还创建了一个列表 现在我想为特定组/用户的特定列表添加“Read”权限 这个网页部件运行良好 但不更新权限。 请帮忙 我正在粘贴下面的代码 protected void Button1_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(TextBox1.Text) || string.IsNull

如何以编程方式向组/用户授予特定列表的“读取”权限?

我已在共享点中手动创建了一个组。 还创建了一个列表

现在我想为特定组/用户的特定列表添加“Read”权限

这个网页部件运行良好

但不更新权限。 请帮忙

我正在粘贴下面的代码

 protected void Button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(TextBox1.Text) || string.IsNullOrEmpty(TextBox2.Text))
            {
                Label4.Text = "Please Enter Some Values";
                //Label4.ForeColor = System.Drawing.Color.Red;
            }
            else
            {

                SPWeb web = SPContext.Current.Web;
                SPGroup group = web.SiteGroups[TextBox2.Text];
                SPWebApplication webApp = web.Site.WebApplication;
                webApp.FormDigestSettings.Enabled = false;
                web.AllowUnsafeUpdates = true;
                SPRoleDefinition rDefination = web.RoleDefinitions.GetByType(SPRoleType.Reader);
                 SPRoleAssignment rAssignment = new SPRoleAssignment(group);

                rAssignment.RoleDefinitionBindings.Add(rDefination);
                SPList list = web.Lists[TextBox1.Text];
                list.BreakRoleInheritance(true);
                //SPItem item = list.
                //item.RoleAssignments.Add(rAssignment);
                list.Update();
                Label4.Text = "Permission is successfully on item";
                //Label4.ForeColor = System.Drawing.Color.Green;
                TextBox1.Text = string.Empty;
                TextBox2.Text = string.Empty;
                web.RoleAssignments.Add(rAssignment);
                web.Update();
                web.AllowUnsafeUpdates = false;
                webApp.FormDigestSettings.Enabled = true;

            }
     }

尝试使用下面的代码。runwithelevatedprivileges将允许简单用户更新列表

SPSecurity.RunWithElevatedPrivileges(delegate()
{
    if (string.IsNullOrEmpty(TextBox1.Text) || string.IsNullOrEmpty(TextBox2.Text))
            {
                Label4.Text = "Please Enter Some Values";
                //Label4.ForeColor = System.Drawing.Color.Red;
            }
            else
            {

                SPWeb web = SPContext.Current.Web;
                SPGroup group = web.SiteGroups[TextBox2.Text];
                SPWebApplication webApp = web.Site.WebApplication;
                webApp.FormDigestSettings.Enabled = false;
                web.AllowUnsafeUpdates = true;
                SPRoleDefinition rDefination = web.RoleDefinitions.GetByType(SPRoleType.Reader);
                 SPRoleAssignment rAssignment = new SPRoleAssignment(group);

                rAssignment.RoleDefinitionBindings.Add(rDefination);
                SPList list = web.Lists[TextBox1.Text];
                list.BreakRoleInheritance(true);
                //SPItem item = list.
                //item.RoleAssignments.Add(rAssignment);
                list.Update();
                Label4.Text = "Permission is successfully on item";
                //Label4.ForeColor = System.Drawing.Color.Green;
                TextBox1.Text = string.Empty;
                TextBox2.Text = string.Empty;
                web.RoleAssignments.Add(rAssignment);
                web.Update();
                web.AllowUnsafeUpdates = false;
                webApp.FormDigestSettings.Enabled = true;

            }

});

我也面临这类问题。我有一个具有只读权限的列表,希望在页面加载时更新该列表。它的工作为管理员用户罚款。但不更新只读用户的列表。
SPListItem listitem = listPositional.Items.Add();
                           listitem["Title"] = "data1";
                           //listitem["Enc"] = "Encrypted data";
                           listitem.Update();
                           listitem.BreakRoleInheritance(false);

                           SPGroup group = myWeb.SiteGroups["Restricted Readers"];

                                                         GrantPermission(listitem, myWeb, SPRoleType.Reader, group);


private static void GrantPermission(SPListItem CurrentListItem, SPWeb oSPWeb, SPRoleType SPRoleType, SPPrincipal SPPrincipal)
    {

        try
        {

            //Create one Role Definition i.e Full Controls, Contribute rights or Read rights etc.
            SPRoleDefinition oSPRoleDefinition = oSPWeb.RoleDefinitions.GetByType(SPRoleType);
            //Create one Role Assignment for the specified SP user or group.
            SPRoleAssignment oSPRoleAssignment = new SPRoleAssignment(SPPrincipal);
            //Bind the role definition to the role assignment object created for the user or group.
            oSPRoleAssignment.RoleDefinitionBindings.Add(oSPRoleDefinition);
            //Add it to the specified list item.
            CurrentListItem.RoleAssignments.Add(oSPRoleAssignment);
            //update the list item so that specified user assignment will have the access.
            CurrentListItem.Update();

        }
        catch (Exception ex)
        {

            throw ex;

        }
        }