Pages

Search This Blog

Monday, May 2, 2011

Hiding Workspace Checkbox while creating new sharepoint Event\Meeting

As per project requirement I was asked to hide a field called 'Workspace' from new event\meeting or editing existing event\meeting.  As 'Workspace' is a Cross Project Link type field so SPField.ShowInDisplayForm, SPField.ShowInEditForm etc do not work fine with this field. To fix that issue I put few lines of code in FeatureActivated() method:
 public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            try
            {               
            SPWeb objSPWeb = (SPWeb)properties.Feature.Parent;
#region Disable Events\Meeting Workspace checkbox
SPList objSPListEvents = objSPWeb.Lists[Event_List”];
SPList objSPListMeetings = objSPWeb.Lists[Meeting_List”];
                                
            if (objSPListEvents != null && objSPListMeetings != null)
            {
SPField objSPFieldWorkSpace = objSPListEvents.Fields[“Workspace_Field”];
SPField objSPFieldMeetingsWorkSpace = objSPListMeetings.Fields[“Workspace_Field”];
if (objSPFieldWorkSpace != null && objSPFieldMeetingsWorkSpace != null)
            {
            objSPFieldWorkSpace.Hidden = true;
            objSPFieldWorkSpace.Update();
            objSPListEvents.Update();

            objSPFieldMeetingsWorkSpace.Hidden = true;
            objSPFieldMeetingsWorkSpace.Update();
            objSPListMeetings.Update();
            }
            }
            #endregion
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Cheers

No comments:

Post a Comment