Agusto Xaverius P Sipahutar

Job:Making some bugs and patch
Moss/Wss,C#,Sql Server,WWF,K2.BlackPearl
Motto : Keep Study and study
See also: Other Geeks@INDC

News




MCP Logo
MCTS Logo

MCP ID# 3542391

My Curiculum Vitae


Agusto Xaverius P S's Facebook profile

Other Article

My Community

My Article/Share Knowledge

Others Moss/Wss Site

My Other Website/Blogs

My Share (Ebook,etc)

Programming Item Security on WSS 3 / Moss

I got this code on the internet how to setting permission on WSS/MOSS folder or it could be item too can be set the security.

 

 /* seeting permision */

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;

namespace ListItemPerms
{
    class Program
    {
        static void Main(string[] args)
        {
            SetListItemPerms();
        }

        static void SetListItemPerms()
        {
            //Get SPWeb object

            SPSite Site = new SPSite("http://<url>"); //e.g., "http://myserver/mysite"
            SPWeb Web = Site.OpenWeb();

            //Get Role Definition from SPWeb

            SPRoleDefinition RoleDefinition = Web.RoleDefinitions.GetByType(SPRoleType.Administrator); //or whichever SPRoleType you choose

            //Get SPListItem

            SPList List = Web.Lists["<list name>"]; //e.g., "Announcements"
            SPListItem ListItem = List.Items[1];

            //Create new Role Assignment
            //Add Role Definition to Role Assignment's Role Definition Bindings

            SPRoleAssignment RoleAssignment = new SPRoleAssignment("<login name>", //e.g., "MYDOMAIN\UserA"
                                                                    "<email address>", //e.g., "
usera@example.com"
                                                                    "<display name>", //e.g., "User A"
                                                                    "<notes>"); //e.g., "Here are some notes."

            RoleAssignment.RoleDefinitionBindings.Add(RoleDefinition);

            //Check for permission inheritance, and break if necessary

            if(!ListItem.HasUniqueRoleAssignments)
            {
                        ListItem.BreakRoleInheritance(true); //pass true to copy role assignments from parent, false to start from scratch
            }           

            //Add Role Assignment to SPListItem's Role Assignment Collection

            ListItem.RoleAssignments.Add(RoleAssignment);
            ListItem.Update();

        }
       
    }
}

 I hope i can used on my project on the client right now, because i need to setting the security and seting worflow on the that list. 

 

Share this post: | | | |
Posted: Nov 22 2007, 12:02 PM by agusto | with 13 comment(s)
Filed under:

Comments

No Comments