I have an event receiver that sets SPField
values based on certain user choices. I'm trying to show/hide one field based on the current user's signed in permissions, but only when the list item is being edited.
First of all, what event does this apply to? Is it ItemAdding
, ItemUpdating
, ItemAdded
, etc.? I've tried each of them with no luck.
public override void ItemUpdating(SPItemEventProperties properties)
{
using (SPWeb web = properties.Web)
{
SPList list = properties.List;
SPListItem item = properties.ListItem;
SPField status = list.Fields["Site Status"];
SPUser user = web.CurrentUser;
bool authorized = list.DoesUserHavePermissions(user, SPBasePermissions.ManageWeb);
if (list != null)
{
if (authorized == true)
{
status.Hidden = true;
//status.ShowInEditForm = true; this never works no matter what
status.Update();
}
else
{
status.Hidden = false;
//status.ShowInEditForm = false; this also never works no matter what
status.Update();
}
}
}
}
So I guess there are 2 questions here. First, what event does this apply to, and second what is wrong with the code?