Monday, April 27, 2009

Customizing Master Page

Because modifying a master page is a long, risky and tedious process, it is recommended that you start with a base minimal master page, such as the one provided on the MSDN Web site at

Saturday, April 25, 2009

Get SPList Schema

If you have the List GUID, use the below to get List Definition Schema

Friday, April 24, 2009

Feature Stapling or Feature/Site Template Associations

As the title imposes the meaning, Feature Stapling is a mechanism to attach (activate) a Feature automatically when a new site is provisioned.

Lets dive back to the past a little to Site Definitions. You generally create a site definition and include a feature in the definition file (onet.xml). Once you are happy with your definition, you would start creating new sites with this definition. Once any one site is created, you dont have liberty to change the definition due to other risk factors etc. So far So Good.

Now, think about a scenario where you really want to add an additional feature for subsequent newly created sites that will be associated with your existing site definition. One of the cool mechanism's is Stapling.

Stapling (Feature Stapling in this case) is the method by which you staple a feature (required) with another feature (like a catalyst/driver/secondary) to drive the required feature. However the catalyst must implement FeatureSiteTemplateAssociation to achieve this.

Step 1: Creating the Primary Requirement Feature - is as simple as creating any other normal feature (say with GUID#1). Nothing new. You can see my previous blog for that.

Step 2: Create the catalyst Feature - Create a new Feature which will have its own Feature.xml with its own GUID (say GUID#2). However the elements file will have the following code instead.

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="">
 <FeatureSiteTemplateAssociation Id="GUID#1" TemplateName="GLOBAL#0" />

The FeatureSiteTemplateAssociation element maps the associations of the GUID#1 to the site definition. Intresting attribute is TemplateName that is meant to specify if you want to staple Globally or at Team Site level. You can achieve it by declaring as shown below.

<FeatureSiteTemplateAssociation Id="GUID#1" TemplateName="STS#1" />

or you can do it together as below.

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="">
 <FeatureSiteTemplateAssociation Id="GUID#1" TemplateName="GLOBAL#0" />
 <FeatureSiteTemplateAssociation Id="GUID#1" TemplateName="STS#1" />

* "GLOBAL" would staple it at the Farm Level and "STS" would staple it to the Team Site Level. Hence, if you want to deploy at both levels, you want to use both together.

1. You cannot apply Feature Stapling to already existing sites. You either have to manually activate it or write a small functionality that would deactivate features on all the site and reactivate.
2. Feature Stapling cannot be applied for 'Blank Sites'.

SPWebApplication IsAdministrationWebApplication Property

public virtual bool IsAdministrationWebApplication { get; set; }


Gets or sets a Boolean value specifying whether the Web application is the Central Administration application.

This property is very useful during applying any specific feature on a web.
For instance, if one doesn't want to apply custom branding feature on CA... check this property and then apply branding if it is not Central Admin (if the requirement says not to apply branding on CA). Other places, use your discretion.

Thursday, April 23, 2009

Issue with Threaded View in Discussion Board as Default View

Scenario: When 'Threaded View' is made as only 'Default View' in Discussion Board, and clicked on the Bread Crumb gives error.

Details: 'Threaded View' technically requires additional query parameters (details of the item) to display the contents of the discussion board. Where as link on the Bread Crumb need 'All Items' mode kind of thing to display the items.

Hence if you try to remove any other view (like flat , subject) the link tries to load the Discussion Board in threaded view and since the extra parameters cannot be loaded, page ends up in error.

Fix: Create a new view 'Subject View' or 'XYZ View' and make it default. Now, the bread crumb view will pick up your new View instead of the Threaded View and everything works fine.

On a side note... you can have 2 default views for Discussion Board.

Wednesday, April 22, 2009

ToolBarMenuButton.CallbackVisibilityPermission Property

I am trying to understand and write more about it. For now, all I have this link.

Sharepoint RightsGroup Element (View)

Links under ListViewWebPart such as 'Add new discussion' needs to be hidden some times based on specific rights.

When you see the ListViewWebPart under xslt mode or using SPD you will find out the CDATA content uder <ListViewXml></ListViewXml> tags.

In general, for the above mentioned example 'Add new discussion' resides under the rights group as below.

  <RightsGroup PermAddListItems="required"/>
  <HTML> To create a new item, click 'Add new discussion' below.

here instead of PermAddListItems which comes with Read Level permissions, i would like to make sure that Read level doesnt have access to 'Add new discussion'. So, i will change replace PermAddListItems="required" to PermManageLists="required".

Now, think of as many places as you can use this.

A complete list of RightsGroup is under this location.

Tuesday, April 21, 2009

SharePoint SafeControl Listing

Lately I was having this pretty good discussion with my friends and colleagues on the SafeControl list in Sharepoint.

Well, you already might have a clear opinion on it, but this is for those who are beginners who want to have strong fundamentals.

Genre: Fundamentals

Scenario / Question: Do we need to safecontrol list every binary we create? For instance, We have third party binaries (Grid Controls) in GAC (Full trust)... but not in safecontrol list and they are referenced and used in webparts with out any issues.

Short Answer : No. Read below.

SafeControl entry in web config only controls the behaviour of WSS Safe Page Parser by allowing a given class deriving from Web.UI.WebPart to be instantiated as a WebPart on the page. this is the only use. if the Type is not a web part (or any number of derivatives like ASCX control templates), there is no use listing it as a safe control.

GAC (and associated full trust) on the other hand controls CAS permissions of any .NET code (not just ASP.NET controls and WPs) and does not intersect with the Safe Page Parser.

Monday, April 20, 2009

SPGridView Paging

Enable Paging option on a SPGridView.


// oSPGridView is your Grid Instance
//Under CreateChildControls()

oSPGridView.PageSize = nPagerSize;
oSPGridView.AllowPaging = true;
oSPGridView.PageIndexChanging += new GridViewPageEventHandler(oSPGridView_PageIndexChanging);

oSPGridView.PagerTemplate = null;

// Under PageIndexChanging Event
void oSPGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
oSPGridView.PageIndex = e.NewPageIndex;

Reading SPWeb Properties

Read Webproperties of a feature.xml.

In feature.xml under <Feature><Properties> tag use the below...

<Property Key="someKey" Value="true" />

From class file read the property value as below...

SPWeb web = SPContext.Current.Site.RootWeb;
if (web.Properties["someKey"] != null)
// web.Properties["someKey"] // Gives the value

Custom Audit in SharePoint using SPAudit

Here is a simple example on how to use custom auditing in sharepoint. I am using SPListItem to audit simple data.

oSPListItem.Audit.WriteAuditEvent(SPAuditEventType.Custom, "SomeDefinition", "<CustomAuditMessage>Hello World!</CustomAuditMessage>");

SPSecurityTrimmedControl and PermissionsString

You shall sooner or later face a situation that you need to create a control under specific (custom) permission levels. SPSecurityTrimmedControl is one control that can give you such features.

A simple SPSecurityTrimmedControl can be added to you page as shown below:

<Sharepoint:SPSecurityTrimmedControl runat="server" PermissionsString="XYZ">

Now, the XYZ can be any of the following as mentioned below.

Scenario: If I need to give specific users permissions to Edit the page; I use below lines of code...

<Sharepoint:SPSecurityTrimmedControl runat="server" PermissionsString="AddAndCustomizePages">
<a href="javascript:MSOLayout_ToggleLayoutMode();">Edit Page</a>

Which means any user who belongs to a group with permissions for 'Adding and Customozing the Pages' can see the hyperlink Edit Page.
List Permissions

Site Permissions

Personal Permissions

Sunday, April 5, 2009

SharePoint Designer

SharePoint Designer 2007 is now free to download and license free :).

follow link here.