I have the following ItemUpdated
event receiver inside my sharepoint farm 2013. now inside my itemupdated
event receiver i am creating a new sub-site, then inside a list titled "Risk & Issue", i am accessing its list content type, and set the title field as hidden inside the list content type and leave the settings as is inside the site content type. so i tried the following code:-
public override void ItemUpdated(SPItemEventProperties properties)
{
base.ItemUpdated(properties);
//create the subsite
SPWeb newSite = spCurrentSite.Webs.Add(curItemID, curItemSiteName, "created automatically after adding a new project item", Convert.ToUInt16(1033), webTemplate, false, false);
//code goes here
newSite.Update();
// loop through the new site lists
for (int i = 0; i < newSite.Lists.Count; i++)
{
if (newSite.Lists[i].Title.ToLower() == "risk & issue")
{
SPContentType riskCT = newSite.Lists[i].ContentTypes[0];
if (riskCT.Fields.ContainsFieldWithStaticName("Title") == true)
{
SPField titlefield= riskCT.Fields.GetFieldByInternalName("Title");
titlefield.Hidden = true;
riskCT.Update();
}
}
}
newSite.Dispose();
}
now when the event receiver runs, it will create a new subsite, and i will not get any exception, but the title field inside the content type will still be set to Required instead of being hidden. so can anyone adivce what is wrong with my code, that is preventing the Title field from being set as hidden inside the list content type??