开发者

How to restrict SharePoint WSS3 users to edit only fields that are in their dedicated views

开发者 https://www.devze.com 2022-12-30 01:43 出处:网络
I have a list with the fields: Title, Client, Project, Description. There is a view for analysts with the fields visible: Title, Project, Description.

I have a list with the fields: Title, Client, Project, Description.

There is a view for analysts with the fields visible: Title, Project, Description.

All is fine so far as the analysts work with their views and not with the lists. But when they need to modify the records clicking on Edit, they see and able to modify the 'Client' field too.

How to prevent 'Client' field to be available for editing by the group? is there a way in WSS or I need to look for 3rd party list comp开发者_Python百科onents?


All fields have a set of properties that determine their visibility in forms, such as "ShowInNewForm", "ShowInEditForm", and "ShowInDisplayForm". There's also some for the file dialog, the list settings page, and a few other places, but that's getting past it. Short answer, yes, you can make the field not show up in the edit form with WSS without needing any 3rd party components.

If you need a field that cannot be seen in the Edit Form by anyone (that is, no one should be able to have it in their form), then you need to modify "ShowInEditForm" to be true. This can't be modified directly through the SharePoint UI, but it is extremely simple using the object model.

If you need certain people to edit it at some point through the SharePoint UI, then you'll instead have to create a custom edit form. That's a bit more complex, so I'll hold off on providing that instruction unless you state you need to go down that route (or someone else passes by this answer and requests it). Nevertheless, it is fully possible with WSS 3.0.

EDIT

If you know already know how to insert inline C# code into an ASPX page, you can perform this very simply using SharePoint Designer. First, follow the instructions from this article, especially make sure you don't delete the default list form web part. Now, in the custom list form you added, make it include every field which anyone will be capable of editing. The last step is to make the form hide those fields for certain people. Let's default them to Visible=false, and flip this switch if the user is allowed them. You can do this either by checking if the current user is part of specified groups, or by checking if the user has a certain permission level only held by people of those groups. You'll basically write some code like the following, I'll use checking for a specified group as the example.

using (SPWeb web = this.Web)
{
    SPUser currUser = web.CurrentUser;
    string[] listOfGroups = { "Group1Name", "Group2Name", "Group3Name" };
    foreach (string groupName in listOfGroups)
    { 
        if (currUser.Groups.Contains(groupName))
        {
    //Repeat this for each Control, refer to them by their ID. For example, this is for a control with the ID txtTitle.
            txtTitle.Visible = true;
        }
    }
}

If you don't know inline code, you'll have to write a custom ASPX page with a code-behind. Copy EditForm.aspx into a new file - you should do this after setting up a Custom List Form as per the article. You could also build a new ASPX page from scratch, but make sure you include all of the necessary Content placeholders for SharePoint pages. Now, the page currently inherits from Microsoft.SharePoint.WebPartPages.WebPartPage. We need to create custom code that inherits from that class, and change the page to inherit that new custom code instead. In the custom code, override one of the OnLoad or OnInit methods, and include your check for the user's permissions there as detailed earlier. Compile the code, deploy it to your SharePoint server, and it should be functional.


If you want to set fields hidden or display them in new form or edit form page of the list...

Go to the list settings. In Advanced Settings, enable "Allow management of content types"

By doing so, you will get a List name Link on the List Setting Page. Open the link and select the fields that you want to hide or uhide using add or remove option.

After saving this, again disable "Allow management of content types" in Advanced Setting...

Thats it :)))

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号