If you are a devleoper and consue the ILP API, you can do so.

Download the latest ilp_api_{version}.zip. Unzip and add reference to the the Chaks.SharePoint.Docs.ILP.dll in your project

You can now use the Extension method EnableItemLevelPermissions on the SPList object.

Below is the declaration of the EnableItemLevelPermissions method:

ilp_enableitemlevelpermissions.png

It accepts ItemLevelPermissionSettings as the only parameter

ilp_itemlevelpermissionsettings.png
  • EnableItemLevelPermissions
    • Specify whether to enable ILP or not
  • DefaultGroups
    • List of default SharePoint groups you want to apply to the items
  • DefaultPermissionLevel
    • The default permission level you want to apply to the items
  • ApplyToExistingItems
    • Specify whether to apply the changes to the existing items or not

You can safely ignore EventReceiverAssembly and EventReceiverClass as it is internally used by the ILP to hook to the proper event receiver. From next release onwards, developers will be able to hook up to their own event receivers using these two peoperties.

Using the API

Below are some code samples on using the API (in Release Versions order):

Release v1.1.0.0
*********************

using Chaks.SharePoint.Docs.ILP;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite spSite = new SPSite("http://sample"))
            {
                using (SPWeb spWeb = spSite.RootWeb)
                {
                    SPList imagesList = spWeb.Lists["Site Collection Images"];

                    List<SPGroup> spGroups = new List<SPGroup>();
                    spGroups.Add(spWeb.SiteGroups[1]);
                    spGroups.Add(spWeb.SiteGroups[2]);

                    ItemLevelPermissionSettings settings = new ItemLevelPermissionSettings
                                                               {
                                                                   EnableItemLevelPermissions = true,
                                                                   DefaultPermissionLevel = spWeb.RoleDefinitions["Full Control"],
                                                                   DefaultGroups = spGroups,
                                                                   ApplyToExistingItems = true,
                                                                   EventReceiverAssembly = "Chaks.SharePoint.Sample, Version=1.0.0.0, Culture=neutral, PublicKeyToken=************************************",
                                                                   EventReceiverClass = "Chaks.SharePoint.Sample.MyListEventReceiver"
                                                               };

                    imagesList.EnableItemLevelPermissions(settings);

                    Console.WriteLine("Permissions applied....Press any key to continue");
                }
            }

            Console.ReadKey();
        }
    }
}


Developers are now able to register their custom event handlers to ILP. Please do remember that if you are using the API to enable ILP & register your custom event handlers, you have to use the API again to disable ILP & un-register your custom event handlers to the corresponding document library or list.

Just leave the EventReceiverAssembly and EventReceiverClass empty if you dont want to use your custom event handler. In that case, the default behaviour will be applied - ILP will use its event handler.

Release v1.0.0.0
*********************

using Chaks.SharePoint.Docs.ILP;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite spSite = new SPSite("http://sample"))
            {
                using (SPWeb spWeb = spSite.RootWeb)
                {
                    SPList imagesList = spWeb.Lists["Site Collection Images"];

                    List<SPGroup> spGroups = new List<SPGroup>();
                    spGroups.Add(spWeb.SiteGroups[1]);
                    spGroups.Add(spWeb.SiteGroups[2]);

                    ItemLevelPermissionSettings settings = new ItemLevelPermissionSettings
                                                               {
                                                                   EnableItemLevelPermissions = true,
                                                                   DefaultPermissionLevel = spWeb.RoleDefinitions["Full Control"],
                                                                   DefaultGroups = spGroups,
                                                                   ApplyToExistingItems = true
                                                               };

                    imagesList.EnableItemLevelPermissions(settings);

                    Console.WriteLine("Permissions applied....Press any key to continue");
                }
            }

            Console.ReadKey();
        }
    }
}


********************************************************************************************************************************************************************************

You can pass null if you dont intend to apply any default permission level and default groups

ItemLevelPermissionSettings settings = new ItemLevelPermissionSettings
{
     EnableItemLevelPermissions = true,
     DefaultPermissionLevel = null;
     DefaultGroups = null;
     ApplyToExistingItems = true
};


Note

Eventhough ILP for Document Libraries is meant only for Document Libraries (as the same suggests), using the API, you can also apply it to a SharePoint List.Please note that, it does not override the SharePoint out of the box Permissions settings and thus if you have already set up unique permissions for a SharePoint list, they will also be applied along with the ILP settings.

Last edited Aug 8, 2009 at 9:17 AM by chakkaradeep, version 6

Comments

No comments yet.