.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Articles >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Hide sharepoint list columns based on user permission on new/edit form

Posted By:Sunil Yadav       Posted Date: June 29, 2010    Points: 50    Category: SharePoint    URL: http://www.dotnetspark.com  

This article explains the scenario when you need to hide columns based on user permission on a sharepoint list while adding or modifying items.

Firstly you need to find out control name when it gets render on NewForm.aspx or EditForm.aspx.

Sharepoint Text columns are TextField which renders as Input type="text". So you need to cast it with TextBox.

Below is the sample code to Enable/Disable to column based on user permission. Remember to add page inherit to your class created below.

public class Permissionsclass : Page { protected override void CreateChildControls() { SPSite site = new SPSite("http://mossportal/"); SPWeb web = site.OpenWeb(); SPList myList = web.Lists["My List"]; SPUser user = web.CurrentUser; bool bPermission = myList.Permissions.DoesUserHavePermissions(SPRights.AddListItems); // find the control id here System.Web.UI.WebControls.TextBox fldAdminComment = (System.Web.UI.WebControls.TextBox)this.FindControl("ctl00$m $g_80f418ab_bb35_4ece_9238_a13ec0c06fd8$ctl00$ctl04$ctl02$ctl00$ctl00$ctl04$ctl00$ctl00$TextField"); System.Web.UI.WebControls.TextBox fldStatus = (System.Web.UI.WebControls.TextBox)this.FindControl("ctl00$m $g_80f418ab_bb35_4ece_9238_a13ec0c06fd8$ctl00$ctl04$ctl00$ctl00$ctl00$ctl04$ctl00$ctl00$TextField"); if (bPermission) { fldAdminComment.Enabled = true; fldStatus.Enabled = true; } else { fldAdminComment.Enabled = false; fldStatus.Enabled = false; } web.Dispose(); }


That's it.

 Subscribe to Articles


Further Readings:

Author: Sammy         Company URL: http://www.dotnetspark.com
Posted Date: August 16, 2010

This looks like what I need. Where exactly do you place this code? Does it fire off automatically or do I need to call it somewhere?
Author: Sunil Yadav         Company URL: http://www.dotnetspark.com
Posted Date: August 17, 2010

You need to inherit this class on your page i.e on Editform.aspx. This can also be placed on custom pages.
For more info refer to my blog


hope it helps.

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend