Friday, March 8, 2013

Hide approve state column from all lists

[Code]

private void hideApproveStateColumn(SPWeb oWeb)
        {            oWeb.AllowUnsafeUpdates = true;
            SPListCollectionAdapter listAdapter = new SPListCollectionAdapter(oWeb.Lists);
            var result = from list in listAdapter                         select list;
            foreach (SPList list in result)            {                if (list.EnableModeration == true)                {                    string ApprovalStatusColumnName = "_ModerationStatus";                    SPView defaultView = list.DefaultView;                    if (defaultView.ViewFields.SchemaXml.Contains(ApprovalStatusColumnName))                    {                        defaultView.ViewFields.Delete(ApprovalStatusColumnName);                        defaultView.Update();                    }                }            }            oWeb.AllowUnsafeUpdates = false;        }

No comments:

Post a Comment