Thursday, March 19, 2009

Showing the page fields/Controls only in edit mode of the SharePoint page

To show the fields only in the Edit mode of the page, add the controls in the following node by editing the page layout of the page.

PublishingWebControls:EditModePanel control is used to show the controls only in the edit mode of the page.

The way we do this is by putting two edit mode panels on the page layout, one configured to render in edit mode, and another configured to render in view mode:

To show in view mode
PublishingWebControls:EditModePanel runat=server id="EditModePanelA" PageDisplayMode="Display">
SharePointWebControls:FieldValue runat="server" id="ImageFieldValue" FieldName="PublishingPageImage"/>

To show in Edit mode only
PublishingWebControls:EditModePanel runat=server id="EditModePanelB">
SharePointWebControls:FieldValue id="ContactEMailId" FieldName="ContactEMail" runat="server" />

The first one will render its contents when people are viewing the page, while the second one will render when people are editing the page

Creating MenuItem in the site Actions menu and adding Security

The application pages and supporting menu items in the Site Actions menu shown so far have been created in a manner so that they are accessible to all users of a site. However, that isn't always desirable. Application pages are often designed to provide information and functionality that should only be accessible to site administrators. The same shows to create a menu item in the Site Actions menu.

This can be installed to sharePoint as a feature as mentioned in the XML below. You can add an attribute named RequireSiteAdministrator and assign it a value of true so that the menu item only displays to those users who are also site administrators.

< CustomAction Id="SiteActionsToolbar" GroupId="SiteActions" Location="Microsoft.SharePoint.StandardMenu" Sequence="1003" Title="Application Page 3" Description="Check out some typical site properties" RequireSiteAdministrator="True" ImageUrl="/_layouts/images/DECISION.GIF">
< UrlAction url="~site/_layouts/CustomApplicationPages/ApplicationPage3.aspx">
< /CustomAction>

After Installing the feature, the SharePoint site looks like

Activating Auditing Programmatically for a Document Library in SharePoint

In the SharePoint (MOSS) object model, SPList objects and SPListItem objects expose an Audit property that makes it possible to configure auditing. The following example shows how to enable auditing in a single document library.

// Open site and Web objects
SPSite siteCollection = new SPSite(http://localhost);
SPWeb site = site.OpenWeb("testweb");

// Open the document library to enable auditing
SPList docLib = site.Lists("documents");

// Turn on auditing flags.
docLib.Audit.AuditFlags = SPAuditMaskType.View

To enable auditing at site collection level
// Open site object
SPSite siteCollection = new SPSite(http://localhost/);
// Enable auditing for the site
siteCollection.Audit.AuditFlags = SPAuditMaskType.All;