Friday, August 7, 2009

SPCustomContextMenu

Hi Guys!

Recently I have got some free time, so I thought of utilizing that time as technically, so I have designed and developed a reusable component for SharePoint list and library, this component will be very useful when you customizing context menu of list , document library and developing workflows

I have seen so many people using below code for customizing SharePoint list context menus. But just think about maintenance

function Custom_AddListMenuItems(m, ctx)
{
Return true;
}

If any changes come in future we need edit the page and modify the javascript and once again we need test that functionality, here we are wasting our valuable time

SPCustomContextMenu

So I have created a feature which will read the xml file and convert into custom context menu the main advantage of this is whenever you change xml file the changes will be automatically reflected in to your custom context menu

This will be very useful when you developing workflows because based on the status of workflow the context menu will change, the administrator will have full control on this no developer interaction

The XML schema looks like this


<?xml version="1.0" encoding="utf-8" ?>
<nodes>
<node>
<sourcefield>
<fieldname>status</fieldname>
<ifeq>open</ifeq>
</sourcefield>
<destfield>
<shownode>
<Name>Assign issue</Name>
<ImageUrl>/SiteCollectionImages/ppubicon.gif</ImageUrl>
<ActionLink>/Pages/TestPage.aspx</ActionLink>
</shownode>
</destfield>
</node>
<node>
<sourcefield>
<fieldname>status</fieldname>
<ifeq>assigned</ifeq>
</sourcefield>
<destfield>
<shownode>
<Name>In Progress</Name>
<ImageUrl>/SiteCollectionImages/ppubicon.gif</ImageUrl>
<ActionLink>/Pages/TestPage.aspx</ActionLink>
</shownode>
</destfield>
<destfield>
<shownode>
<Name>Paused</Name>
<ImageUrl>/SiteCollectionImages/ppubicon.gif</ImageUrl>
<ActionLink>/Pages/TestPage.aspx</ActionLink>
</shownode>
</destfield>
<destfield>
<shownode>
<Name>Set In Progress</Name>
<ImageUrl>/SiteCollectionImages/ppubicon.gif</ImageUrl>
<ActionLink>/Pages/TestPage.aspx</ActionLink>
</shownode>
</destfield>
</node>
<node>
<sourcefield>
<fieldname>status</fieldname>
<ifeq>in progress</ifeq>
</sourcefield>
<destfield>
<shownode>
<Name>Paused</Name>
<ImageUrl>/SiteCollectionImages/ppubicon.gif</ImageUrl>
<ActionLink>/Pages/TestPage.aspx</ActionLink>
</shownode>
</destfield>
<destfield>
<shownode>
<Name>Resolved</Name>
<ImageUrl>/SiteCollectionImages/ppubicon.gif</ImageUrl>
<ActionLink>/Pages/TestPage.aspx</ActionLink>
</shownode>
</destfield>
</node>
<node>
<sourcefield>
<fieldname>status</fieldname>
<ifeq>resolved</ifeq>
</sourcefield>
<destfield>
<shownode>
<Name>Re-Opened</Name>
<ImageUrl>/SiteCollectionImages/ppubicon.gif</ImageUrl>
<ActionLink>/Pages/TestPage.aspx</ActionLink>
</shownode>
</destfield>
<destfield>
<shownode>
<Name>Closed</Name>
<ImageUrl>/SiteCollectionImages/ppubicon.gif</ImageUrl>
<ActionLink>/Pages/TestPage.aspx</ActionLink>
</shownode>
</destfield>
</node>
<node>
<sourcefield>
<fieldname>status</fieldname>
<ifeq>re-opened</ifeq>
</sourcefield>
<destfield>
<shownode>
<Name>Assign issue</Name>
<ImageUrl>/SiteCollectionImages/ppubicon.gif</ImageUrl>
<ActionLink>/Pages/TestPage.aspx</ActionLink>
</shownode>
</destfield>
</node>
<node>
<sourcefield>
<fieldname>status</fieldname>
<ifeq>paused</ifeq>
</sourcefield>
<destfield>
<shownode>
<Name>Set in progress</Name>
<ImageUrl>/SiteCollectionImages/ppubicon.gif</ImageUrl>
<ActionLink>/Pages/TestPage.aspx</ActionLink>
</shownode>
</destfield>
</node>

</nodes>

Here the <sourcefield> tag talks about workflow status and <destfield> talks about what to display in custom context menu

I have a issue tracking list as shown in fig





After installing and activating the feature the issue tracking list looks like below see it displays custom context menu based on status of workflow




Using this feature you can modify your custom context menu in minutes

Please mail me for source code raja.mandalapu@gmail.com

Happy coding...

Long time back I have posted an article on creating page layouts using SharePoint user interface and designer, now I am going to explain how to create page layouts using features


In this article, I am going to use WSPBuilder for building and deploying SharePoint solution, the main advantage of WSPBuilder is no need of creating manifest.xml , DDf file and cab file, the WSPBuilder will take care of creating all these things, so this will simplify our process
First, I am going to explain what are the entire things do we need for building SharePoint page layouts using features


Site Columns


A site column is a reusable column definition, or template, that you can assign to multiple lists across multiple SharePoint sites. These columns are directly mapped to table columns in SharePoint database


Her e I have created three columns Activity Name, Activity ID, Activity Image,


While creating site columns please make sure that each column have its own unique ID
You can get Unique ID using GUID tool


VS2008->Tools->Create GUID->Registry Format->Copy





Type="Text"
Name="ActivityName"
DisplayName="Activity Name"
StaticName="Activity Name"
Hidden="FALSE"
Required="FALSE"
Group="Activity Columns"
Sealed="FALSE" />
Type="Text"
Name="Activity ID"
DisplayName="Activity ID"
StaticName="Activity ID"
Hidden="FALSE"
Group="Activity Columns"
Required="FALSE"
Sealed="FALSE" />
Type="Image"
Name="Activity Image"
DisplayName="Activity Image"
StaticName="Activity Image"
Hidden="FALSE"
Group="Activity Columns"
Required="FALSE"
Sealed="FALSE" />



Site Content Type


Suppose if you want to manage your organization information in meaning full way across site collection then you can go for Site content types


A content type is a reusable collection of settings you want to apply to a certain category of content. Content types enable you to manage the metadata and behaviors of a document or item type in a centralized, reusable way


Here I have created activity content type that tells to the client that this content type belongs to only activity information


Every content type has FieldRef properties, these properties have a reference to site columns ID’s, that means this field(Site Column)and FieldRef both are pointing to same reference, so whenever we update site column’s that will automatically reflect in content type columns also
See below code all FieldRef Id’s are pointing to sit columns ID’s, if you want you can override some of the properties name, description etc…


Using below code we have created a content type, this is simple content type, it does not do anything so, we have to attach this to base page content type using Content type ID


The content type ID is the combination of base page ID and custom GUID which are separated by 00


Please refer MSDN link for more info on content type id http://msdn.microsoft.com/en-us/library/aa543822.aspx




Name="ActivityContentType"
Group="Demo"
Description="Demo Content Type"
Version="0">









Layout page


I suggest you guys create layout page using SharePoint designer and copy into your feature folder, so that you will not face any kind of problems and your work will be smooth


Below page is the which I have created using SharePoint designer


All the SharePoint controls of this layout page have a reference to site columns using Fieldname property, the Fieldname is the name of the site column


<%@ Page language="C#" Inherits="Microsoft.SharePoint.Publishing.PublishingLayoutPage,Microsoft.SharePoint.Publishing,Version=12.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" meta:webpartpageexpansion="full" meta:progid="SharePoint.WebPartPage.Document" %>
<%@ Register Tagprefix="SharePointWebControls" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="PublishingWebControls" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="PublishingNavigation" Namespace="Microsoft.SharePoint.Publishing.Navigation" Assembly="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>














ProvisionedFiles.xml

I am using module element for deploying our page in master page gallery












Feature.xml

Title="PageLayoutDemo"
Description="Description for PageLayoutDemo"
Version="12.0.0.0"
Hidden="FALSE"
Scope="Site"
DefaultResourceFile="core"
xmlns="http://schemas.microsoft.com/sharepoint/">










So, we have created all necessary files which are required to create pagelayout, now we have to deploy all these files using features


I am using WSPBuilder for deploying all these files, I have posted an article on WSPBuilder please check it, if you need more info