SharePoint List Item Read Security and Write Security

Many a times, i’ve seen in MSDN Forums where people asking for the much granular-level of list security like who can read the list items and who can write/update t sayihe list items. There are couple of properties called ReadSecurity and Write Security in the SPListClass, that provides the more granular level of security.

The ReadSecurity property of the SPList gets or sets the Read security setting for the list. It can have the possible values of 1 or 2.

1- indicates all users can read the list items

2 – indicates the users can read the items only that they create

The WriteSecurity property of the SPList gets or sets the Read security setting for the list. It can have the possible values of 1, 2 and 4.

1 – Indicates that all the users can modify the all the items

2- Indicates the users can modify the items that they create

4 – Users cannot modify any list item

 Subscribe to my post

Create Custom Tool Parts for SharePoint Web Parts

What is a custom tool part ?

The Custom tool part is part of the web part infrastructure, that helps us to create a custom user interface for the web part properties that goes beyond the capabilities of the default property pane.

When do we need a custom tool part ?

Let’s say, If we need to create a web part property of type dropdown, we need to create a custom tool part. This is not supported out-of-box in the web part framework. I’ve the similar requirement of creating a custom web part property of type drop-down, So i went ahead and implemented the custom tool parts. Here are the steps to create a custom tool part.  

 public class SampleToolPart : Microsoft.SharePoint.WebPartPages.ToolPart
    {
        //create an instance of the dropdown control to be used in the custom tool part 
        System.Web.UI.WebControls.DropDownList oDropDown = new System.Web.UI.WebControls.DropDownList();

        // Reference to the parent web part
        SampleWebPart oSampleWebPart = null;

On the constructor method of the tool part class, just set the title of the tool part. In this case i'm going to display the 
vendor names to the user
So i naming the title as select a vendor.
        public SampleToolPart()
        {

            // Set the title for the custom tool part
            this.Title = "Select a Vendor";

        }

        protected override void CreateChildControls()
        {
            try
            {

            //Get the instance of the parent web part on which this tool part is to be hosted
            oSampleWebPart = (SampleWebPart)ParentToolPane.SelectedWebPart; 
            //Get the instance of the current site collection
            SPSite oSPSite = SPControl.GetContextSite(HttpContext.Current);
            //Get the instance of the current site (spweb)
            Guid currentsiteid = SPControl.GetContextWeb(HttpContext.Current).ID;

            using (SPWeb oSPWeb = oSPSite.OpenWeb(currentsiteid))   

                {
In the following few lines of code, i'm reading the list of vendors from the sharepoint custom list 'VendorList' and binding it to the sharepoint custom tool part. 
                    SPList oProviderMaster = oSPWeb.Lists["VendorList"];
                    foreach (SPListItem oSPListItem in oProviderMaster.Items)
                    {

                        string sProviderName = oSPListItem["VendorName"].ToString();
                        oDropDown.Items.Add(sProviderName);
                    }

                }

            // Add the dropdown to the actual toolpart controls
            this.Controls.Add(oDropDown);
            base.CreateChildControls();
            }
            catch (Exception ex)
            {

            }

        }

When the user choses the item from the dropdown of the custom tool part and clicks 'Apply Changes', grab the selected item from 
the dropdown list and assign this value to a public property declared in the parent web part, where the tool part is hosted.
        public override void ApplyChanges()
        {
            try
            {
                if (!(oDropDown.SelectedItem == null))
                {
                    oSampleWebPart.SelectVendor = oDropDown.SelectedValue;
                }

            }
            catch (Exception ex)
            {

               //handle exceptions here
            }            

        }   

    }

 Subscribe to my post