Thursday, December 30, 2010

Redirect to a Page in custom Site Definition - SharePoint

A Site Definition defines a unique type of Microsoft SharePoint Foundation Web site. There are several site definitions built into SharePoint Foundation. A site definition can include more than one site definition configuration. A SharePoint Foundation Web site is based on particular site definition configuration. For this reason, a site definition may be thought as a family of configurations, although some families contain only one configuration.
  • Site Definitions are the foundations on which all sites and user templates are built.
  • Site Definitions are predefined components needs to be included when a site was created in SharePoint server.
  • Site Definition contains information of Web Part , Lists, Features and navigation bars to be included in the site.

The following are the four site definitions whose configurations can be used to create new Web sites.
  1. STS includes the site definition configurations for, Blank Site, Team Site, and Document Workspace. 
  2. MPS includes the site definition configurations for Basic Meeting Workspace, Blank Meeting Workspace, Decision Meeting Workspace, Social Meeting Workspace, and Multipage Meeting Workspace.
  3. BLOG provides a site definition configuration for blogs.
  4. SGS provides a site definition configuration for Group Work Site.


Redirecting to a custom page, for example like custom settings page, once a new site is created, using custom site definition. This functionality can be also used to have a delayed redirection to site home page, when we perform any site provisioning activities like updating/ modifying the properties of webparts, available on the home page, at runtime.


Assuming that the reader has basic idea working with a custom Site Definition in SharePoint, I m explaining in the below solution. All the configuration we are going to make for achieving this functionality will be done in ONET.XML file only, for our custom site definition with the publishing template.

So here in this solution I m using Publishing Site template, as publishing site has a Redirect page layout, which can be used to create a webpage in the pages library, when the template is being applied.

Step 1: Activating "RedirectPageContentTypeBinding" Feature in the WebFeatures section

This is a very important step, as on activating this feature, the Pages library is configured with Redirect Page Content Type. By default when the Pages library is created in Publishing site, Redirect page content type will not be available. So as to bind this content type "RedirectPageContentTypeBinding" has to be activated, which allows us to create a new page using Redirect Page Layout.

Step 2: Creating a Redirect Page in the pages library

Here we are creating new pages in the Pages Library, using the content type based upon our requirement.

Observe the RedirectURL property, we are explicitly providing the path of default welcome page in the new site going to be created. "~Site" fetches the absolute URL of the site being created, where as "~SiteCollection" fetches the absolute URL of the Site Collection, where the new site is being created.
RedirectURL property can be changed based upon your requirement.

Note: XML folder in your custom Site definition should have the pages above mentioned, along with ONET.XML
Folder structure should be as below:

 --- CustomSiteDefinitionName

Step 3: Specifying Redirect page to open once new site is successfully created

Add the below tag in the Configuration Tag, which specifies, a particular page to be executed once the new site is created. Default behaviour without this tag is to open home page of the site.

Deploy the site definition & create a new site based upon the custom template.

Thursday, November 11, 2010

PushPin to show or hide DIV and maintain state across pages and Users using JQuery

JQuery has very cool features, providing the wide range of plugins to play around with your webpage. Here in this post I m going to discuss regarding a requirement I had to make use of JQuery to maintain the state of a DIV across pages, as well as across Users logged into the application.


This requirement is to provide interface for searching certain content in the SharePoint List based upon the keywords. This search window/pane should have the capability of toggle, as well as the capability of fixing/pin down (stopping toggle i.e showing the DIV) which should be maintained across the pages in the application untill the user either closes the pane or unfix. Also, this provision should be available as per the User choice, logged in to the application.

For better understanding we shall consider two user's named User1 & User2. When User1 loggs in to the application and prefers to pin down the DIV after showing DIV by toggle, that DIV should be in open state, in all the pages being traversed, untill preferred to pin up. But this preference should not reflect to User2, as this user might not prefer to search or looking into the DIV.

  1. Maintaining the Open/Close state across all pages based upon the preference to show/hide respectively.
  2. Maintain the Open/Close state based upon the logged in User preference to show/hide respectively.

  1. Add Script References for
    JQuery Plugin:

    Sessions Plugin:

    JSON Plugin:
  2. Create a DIV tag holding all your content as below:
    Note:Styles & images are from JQuery UI Smoothness theme.
  3. Add the below script in the head tag
    $(document).ready(function() {
     $.namesession.set("LoggedInUser",$().SPServices.SPGetCurrentUser({fieldName: "UserName", debug: false}));
     var SearchWindowStatus= ($.namesession.get('SearchWindowStatus_'+$.namesession.get('LoggedInUser',''), '')!= '')?$.namesession.get('SearchWindowStatus_'+$.namesession.get('LoggedInUser',''), '') :$.namesession.set('SearchWindowStatus_'+$.namesession.get('LoggedInUser',''),false);
      $("a[id$=anchorPinPoint]").children().removeClass('ui-icon-pin-w').addClass('ui-icon-pin-s').attr('title','Keep Search Closed');  
     $(this).click(function() {
           mouseover:function() {
         mouseout:function() {
        focus:function() {
        blur:function() {
        click:function() { 
         return false;
     function TogglePinPoint(ctrl)
        $(ctrl).children().removeClass('ui-icon-pin-w').addClass('ui-icon-pin-s').attr('title','Keep Search Closed');  
       }else if($(ctrl).children().hasClass('ui-icon-pin-s'))
        $(ctrl).children().removeClass('ui-icon-pin-s').addClass('ui-icon-pin-w').attr('title','Keep Search Open');  

Note: Ensure your web.config file is configured for AJAX & JSON
Enable SessionState is set to true in the config file

Wednesday, November 10, 2010

Folders in SharePoint Pages Library for Publishing Site

SharePoint Publishing site template has Pages Document Library, which is a repository for pages with a flexibility of creating pages based upon Page Layouts. Pages created in this library by default are configured with three content types Pages, Article Page & Welcome Page each having their own fields based upon necessity.

Pages Library is flexible in creating pages with different layouts, based upon the design & requirement, but does not have a provision to create pages in folders & access them as per the sitemap/ breadcrumbs, as we create in a basic document library. We can go to advanced settings of the library & configure for showing "New Folder" under the New Menu, even though when we create a page under the folders, it is saved under root folder of the library which does not meet our purpose.

         So here in this post, I would like to share one of the solution I implemented in our project, which sufficed very well using  Pages Library for creating pages in the folders.

           The process of troubleshooting started from creating a  new page. In the publishing site when we try to create a new page either from menu option under "Site Actions" or from the "New Menu" in library, we are redirected to "CreatePage.aspx" available under layouts virtual directory. So this is the page where we can customize as per our requirement.

Steps to recreate:

Building Custom page for creating a page:
    1. Copy the "CreatePage.aspx" available in the layouts folder of SharePoint 12 hive & place it in the same directory or else in your custom directory and rename with a custom name as "CreatePage_Custom.aspx".
    2. Open the CreatePage_Custom.aspx in designer or visual studio and search for the tag  
      Set the property "Visible=false" as this is the control which holds name of the Pages library.
      Note: Do not delete this tag, there is a reference in the code behind.
    3. Add the below directive to have publishing assembly reference
      <%@ Import Namespace="Microsoft.SharePoint.Publishing" %>
    4. Microsoft.SharePoint.Publishing.Internal.CodeBehind.CreatePage is the class in the code behind, but the respective methods are not exposed. So the next option is inline coding in the page, where we use custom event of the submit button to have our functilnality to add the page in the Pages library.
      protected void OnCustomSubmit(Object sender, EventArgs e)
        string newPageUrl = "";
       SPWeb web = SPContext.Current.Web;
       PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);
       PageLayout[] layouts = publishingWeb.GetAvailablePageLayouts();
       int layoutItemId = Convert.ToInt32(pageTemplatePicker.SelectedValue);
       PageLayout layout = FindLayoutById(layoutItemId,publishingWeb);
       string pageName = urlNameTextBox.Text + ".aspx";
       PublishingPage newPage = publishingWeb.GetPublishingPages().Add(Request.QueryString["RootFolder"].ToString() + "/" + pageName, layout);
       newPageUrl = web.Url + "/" + newPage.Url; // Here you can append the Querystring if you want to show the created page in the Edit Mode.
       newPage.Title = titleTextBox.Text;
       newPage.Description = descriptionTextBox.Text;
      protected PageLayout FindLayoutById(int layoutItemId,PublishingWeb localPublishingweb)
       SPListItem itemById = localPublishingweb.Web.Site.RootWeb.GetCatalog(SPListTemplateType.MasterPageCatalog).Items.GetItemById(layoutItemId);
       if (itemById == null)
        return null;
       return new PageLayout(itemById);

    5. Refer the server click event to the custom event cretaed above.
    6. Creating a custom content type:
    7. Deploy content type to the web application Add this new custom content type to the Pages library from the library settings.
    8. Allow library to display New Folder option in New Menu, for creating sub folders.
    9. Create a page using the new content type available under New Menu.

If there is a requirement to create a page from the menu item under Site Actions, please refer to this post.

Saturday, July 3, 2010

SharePoint 2010 Virtual Machine for Evaluation

Virtual Machine running Microsoft SharePoint Server 2010, OCS, Web Applications, FAST Search, Project Server, Project Pro Plus 2010, Visio, Project, SQL Server 2008 R2 and Exchange Server 2010 were published by Microsoft. This download contains a two Windows Server 2008 R2 Hyper-V Virtual Machine set for evaluating and demonstrating Office 2010, SharePoint 2010 and Project Server 2010 – including ECM and PerformancePoint Services

Active directory has been preconfigured with over 200 “demo” users with metadata in an organizational structure. All of these user profiles have been imported and indexed for search within SharePoint Server 2010.

SharePoint Server 2010 has been configured in a “Complete” farm using the default SQL Server 2008 R2 instance. A default site has been created using the Team Site template at and a FAST Search Center at

Get it from:

Virtual machine “a” contains the following pre-configured software:
  1. Windows Server 2008 R2 Standard Evaluation Edition x64, running as an Active Directory Domain Controller for the “CONTOSO.COM” domain with DNS and WINS
  2. Microsoft SQL Server 2008 R2 Enterprise Edition with Analysis, Notification, and Reporting Services
  3. Microsoft Office Communication Server 2007 R2
  4. Microsoft Visual Studio 2010
  5. Microsoft SharePoint Server 2010 Enterprise Edition
  6. Microsoft Office Web Applications
  7. Microsoft FAST Search for SharePoint 2010
  8. Microsoft Project Server 2010
  9. Microsoft Office Professional Plus 2010
  10. Microsoft Visio 2010
  11. Microsoft Project 2010
  12. Microsoft Office Communicator 2007 R2
Virtual machine “b” contains the following pre-configured software:
  1. Windows Server 2008 R2 Standard Evaluation Edition x64, joined to the “CONTOSO.COM” domain
  2. Microsoft Exchange Server 2010

SharePoint 2010 Virtual Labs

We know SharePoint 2010 is a very advanced product in terms of features, capabilities and infrastructure etc. In this scenarios setting up an environment for ourselves is a difficult process atleaset to evaluate the product.

Eventhough now we can install SharePoint 2010 in Windows 7 & Server 2008 they need to be X-64 bit. Upgrading our machines accordingly might involve some investment. So now we have a Virtual labs provided by Microsoft to evaluate the features listed below.

It's our turn to to explore and update to new technologies provided by SharePoint 2010.
Test drive SharePoint 2010 in a Virtual lab. Take part and see how Microsoft Office SharePoint Server supports all intranet, extranet, and Web applications across an enterprise within one integrated platform.

Virtual labs cover the following:
  • MSDN Virtual Lab: Client Object Model
  • MSDN Virtual Lab: Customizing MySites
  • MSDN Virtual Lab: Designing Lists and Schemas 
  • MSDN Virtual Lab: Developing a BCS External Content Type with Visual Studio 2010 
  • MSDN Virtual Lab: Developing a Sandboxed Solution with Web Parts 
  • MSDN Virtual Lab: Developing a Visual Web Part in Visual Studio 2010 
  • MSDN Virtual Lab: Developing Business Intelligence Applications 
  • MSDN Virtual Lab: Enterprise Content Management 
  • MSDN Virtual Lab: Getting Started with SharePoint 2010 
  • MSDN Virtual Lab: LINQ to SharePoint 2010 
  • MSDN Virtual Lab: SharePoint 2010 User Interface Advancements 
  • MSDN Virtual Lab: Visual Studio SharePoint Tools 
  • MSDN Virtual Lab: WorkflowMSDN Virtual Lab: Workflow

Wednesday, April 7, 2010

Handling ClientID issues in SharePoint Webparts & jQuery

In ASP.NET/SharePoint a Control has a fully qualified ID that can be deduced from the control hierarchy and can be accessed with the properties ClientID or UniqueID. It then becomes the unique id or name of rendered html controls. It makes sense that these properties should be used right after the control hierarchy is completely defined, that means before the rendering, therefore in the PreRender.

What is not so well known is that accessing those two properties sets the _cachedUniqueID member, which sets irrevocably the ID to a control. That's why using these properties in ItemCreated events, for example, makes the html id of controls to remain the default defined one.

Example: In a DataList, you have an item template that contains a control, let's call it Control1. The rendered id in html will look like this: ctl00_m_g_aaf13d41_fc78_40be_81d5_2f40e534844f_txtName, but if you use ClientID inside the DataList_ItemCreated event, the rendered html id will be just Control1, thus making any javascript manipulation futile.

Of course, one could create a method to return the UniqueID without setting the cached value, since there are moments when the partial hierarchy is enough to define a proper id. Unfortunately, for controls without a specific and declared id, ASP.NET creates and automatic ID like ctl[number] or _ctl[number] and, of course, those methods and fields are all private or internal. One could use Reflection to get to them, but what would be the point?

UniqueID and ClientID are overridable, though, so one can change their behaviour in user defined controls.

Solution for handling in jQuery, Javascript & SharePoint Webparts (C#).

jQuery is fantastic! It makes client-side development faster and countless plug-ins are available for just about every need. Using jQuery with Asp.NET Web-Forms gets aggravating when dealing with nested server controls. ClientID’s get appended when using ASP.NET Master Pages. Objects in JavaScript tend to look like this:
The difficulty of the issue above is that, in order to get the element txtName, It’s necessary to know the full “path”. It’s quite aggravating to refer to get the object using the method below:
This becomes a big problem when developing server controls or web parts that may be used in a typical ASP.NET application or SharePoint. You cannot hard-code the path above if you don’t know the full path of the control.

Fortunately, there are a few ways to get around this. There are three, in particular, I will mention. The first is the jQuery equivalent to the standard JavaScript method:
This can be done in jQuery by using:
The second jQuery method does not require server tags. This method searches through all tags and looks for an element ending with the specified text. The jQuery code for this method is shown below:
There are, of course, drawbacks to both methods above. The first is fast, but requires server tags. It’s fast, but it just looks messy. Also, it will not work with external script files. The second alternative is clean, but it can be slow. As I said earlier, there are several other alternatives, but these two are the ones I find myself using the most.

The third registering Javascript in C# code behind.
Page.ClientScript.RegisterStartupScript(GetType(), "saveScript",

String.Format("function EnableSave( isDisabled )"+

"{{ var saveButton = document.getElementById(\"{0}\");"+

"saveButton.disabled=isDisabled;}}", btnSave.ClientID), true);

Do not forget to call this script after controls have been loaded, I mean after Controls.Add(); in CreateChildControls method while developing webparts.