Archive for the ‘SharePoint 2010’ Category

Add Links in SummaryLinksWebpart using PowerShell scripting

May 23rd, 2011 Comments off

More on the automation and adding data in other webparts. In previous post I talked about loading data in ContentEditorWebpart. Now look at SummaryLinkWebpart . Recently when i was working with SummaryLinkWebpart. I realised it is a bit different then other web parts to load links in summaryEditorWebpart. I looked for the internet but I couldn’t find any single example for SummaryLinksWebpart with power shell. So here is the example for others. I hope it will help some folks.

$webpart = new-object  $typeName
$webpartType = $webpart.GetType().ToString()

if($webpartType -eq “Microsoft.SharePoint.WebPartPages.ContentEditorWebPart”)
               $keyValuePairs = $values.split(“,”)
               foreach ($keyValuePair in $keyValuePairs)
                       $keyValueArray = $keyValuePair.Split(“|”)

                       [string]$propertyName = $keyValueArray[0].Trim()
                       [string]$propertyValue = $keyValueArray[1].Trim()

                       $sumLink = New-Object Microsoft.SharePoint.Publishing.SummaryLink $propertyName
                       $sumLink.LinkUrl = $propertyValue
                       $webpart.SummaryLinkValue = $webpart.SummaryLinkValue


Load data in ContentEditorWebpart using PowerShell scripting

May 23rd, 2011 Comments off

If you are working on SharePoint content automation then powershell scripts are the most talked item. But sometime it is very difficult to find the right way to load data in web parts. For different web parts you have to treat differently. Here is the example to load data in ContentEditorWebpart.
I have a powershell function, where I’m passing some values including web part type and HtmlContent. HtmlContent is the text I want to set in ContentEditorWebpart.

$webpart = new-object  $typeName
$webpartType = $webpart.GetType().ToString()

if($webpartType -eq “Microsoft.SharePoint.WebPartPages.ContentEditorWebPart”)
              [string]$content = $HtmlContent.ToString()
              $docXml = New-Object System.Xml.XmlDocument
              $contentXml = $docXml.CreateElement(“Content”)

              $webpart.Content = $contentXml

I hope it will help.


Hide the ‘Pages’ library in SharePoint breadcrumb

May 11th, 2011 Comments off

SharePoint breadcrumb is a nice feature to have on the pages. But it doesn’t fit very easily in usual scenario. If you also want to get rid of ‘Pages’ library link in the breadcrumb of a publishing site then see the below instructions.

Normal breadcrumb

My Portal -> Pages -> Test Page1

Updated breadcrumb

My Portal -> Test Page1

Then change the breadcrump source provide to CurrentNavSiteMapProviderNoEncode.  You have to change this in SiteMapPath tag like this…..

<asp:SiteMapPath SiteMapProvider=”CurrentNavSiteMapProviderNoEncode” id=”ContentMap” SkipLinkText=”" NodeStyle-CssClass=“ms-sitemapdirectional runat=“server”/>

 Now when we use CurrentNavSiteMapProviderNoEncode, we have to make sure that ‘Show Pages’ is true for current navigation. Even if you don’t want to display pages on the left navigation you have to enable it. Then you can hide your pages one by one from the navigation settings.


Unique Column/Field in SharePoint List

August 9th, 2010 6 comments

It is always a desire to have unique field in SharePoint list. Sometimes you have to replicate a database table and sometimes it could be a special requirement. Recently when I have been asked to have a unique field in a SharePoint list, I searched for it. Thanks to CodePlex. There is a solution called Unique Column Policy.

It is actually a feature. It creates a new information policy that allows you to specify a column in a list or library that should have unique values. Unfortunately on the website there is not enough information on how to use it. So I created this blog, I will show how it works.

First of all you need to download it. You can download it from this link. (Download). Then you need to install it on your SharePoint server. For this addsolution to solution store.

stsadm –o addsolution –filename UniqueColumnPolicy.wsp

Now deploy the solution. You can deploy it either from the stsadm command or you can deploy it using the SharePoint Central Administration site. This solution deploys globally. So you cannot just deploy it for a single site collection. Once your solution is deployed. Now you can create unique columns in SharePoint lists.

In order to, apply it on a column. Create a new column in a SharePoint list. Now open the list settings page and open the Information management Policy Settings link.

List Settings Page

In order to, apply it on a column. Create a new column in a SharePoint list. Now open the list settings page and open the Information management Policy Settings link. Select ‘Define a Policy’ and click ‘OK’.

Information Management Policy Settings

It will open edit policy page. Now select ‘Enable Unique Column Policy’.

Edit PolicySelect the field you want to use for unique values.

Select a field

Now when you try to add the same value you used before in unique column. It will give you an error like this.

Unique Column ErrorIt will show the same error when you try to update and item and give it same value you used before in any other list item. Good thing is this also works with datasheet view.

DataSheet View

Like in the above image, we tried to use the same value UC_999 in unique column field. When we moved to next column. It displayed an error icon in front of the affected row. This is the error to notify user that duplicated values are not allowed in this column. Click on the icon and you can see more details.

DataSheet View - Error Details

In simple words this feature is amazing, and it gives more power to SharePoint list.

I hope this will help implementing unique column/field in SharePoint list.

Create Item Workflow – SharePoint Designer 2010

May 30th, 2010 Comments off

Sometime you have to create a new list item in a different list on the list item changed or list item created events. It can be to create an announcement on a list item created or changed. In these cases you also like to use the originator list item properties in new list item.
In order to create this workflow using SharePoint Designer 2010 we will use the same approach as in my previous blog. We just do changes in the workflow Action. So create a new workflow CreateItems in SharePoint Designer 2010. You can find more help on creating workflows using SharePoint Designer 2010 here.

For this demonstration I will create a workflow which creates an item in a list name ParentList on item created and item changed of Announcements list. For this I created three new fields in custom list ParentList. These columns names are listName, ItemGuid and ItemTitle. All these are single line fields. And we will assign values in these columns through workflow.
Open Action in the top ribbon of the workflow setting screen in SharePoint Designer 2010. Select Create List Item option. It will create a standard statement for Create List Item Action. Now click on this list and select ParentList.
Click on the ListName in fields and select modify. Add value Announcements as list name. Then add a new field for column ListItem. For value select the function button (fx) and then select the Current Item in Data source and select the GUID in Field from source. Click Ok finally.

Add another field for ItemTitle column and select the Current Item and Title instaed of GUID.

It will actually tell workflow to assign these values to newly created item. In this case it is assigning the Announcements list item GUID and title to new item. Also we added Announcements as a text for ListName here.

Now save the workflow and then from workflows setting screen change the Start Options. Select the list item created and list item changed there. After doing all these settings just publsih it.

Once this workflow is deployed on the site, open the site and add new item in Announcements list. It will create a new item in ParentList and assign Announcements list item GUID and title to the specified fields of newly created ParentList item.

Isn’t this very simple and cool

Have fun.

Copy Item Workflow using SharePoint Designer 2010

May 30th, 2010 15 comments

SharePoint Designer 2010 comes with huge improvements in its features. One of the very amazing improvements is designer’s workflows.

Today I’m going to create a list item workflow in SharePoint Designer 2010. This is a simple workflow that you create in several cases. For this demonstration I have created a TeamSite. You can create this workflow for any site.

What we will achieve from this workflow

I have a default announcement list. And then I created another list with the name CopiedAnnouncement with announcement list template. Now I want to create a workflow for announcement list so when I create or change an item in announcement list it will copy the item in CopiedAnnouncement list. Both the lists are identical in structure.

Also I edited my site’s home page to display both lists. For this
Click on Edit Page under Site Actions
Click on Insert under Editing Tools
Select Existing List
Select Announcements and CopiedAnnouncements one by one.

Purpose of displaying lists on the same page is just to see workflows result quickly.

Now come to the main task, and open your site in SharePoint Designer 2010. In order to create a new workflow, click on File menu and select Add Item. Then select the List Workflow under Workflows tab.

Add CopyItem as the name of new workflow. And select the Announcements in the list drop down. Your new workflow will be attached to the selected list.

When ypu click on Create, it will show a popup message to download data for workflow.

Once it completes the downlaod and load the workflow page. Then click on Edit Workflow link.

Now on this screen you can add Conditions and Actions for your workflow. My workflow is very simple and not using any condition so I will just add as Action straight away. Click on the Action from the top ribbon and then select the Copy List Item.

It will create a standard Copy List item Action.

Now select the Current Item for first option and select CopiedAnnouncements for second option. It is pretty straight forward that this action is saying to copy the current list item to selected list.

Now Click on the Save, it will show a save progress message.

Now choose the Start Option. There are three options to trigger a workflow. Start manually, on List Item Created and on List Item Changed. In my case I selected for List item Created. You can find these options under Start Options on the main workflow setting screen.

Now click on the Publish from the top ribbon. This will deploy the workflow on the site and also attached it to the already selected list. Making life easy. When your workflow is deployed, you can verify it by looking into the list workflow setting. CopyItem should be visible there and will show 0 numbers of workflows running at this stage.

Now it is the time to see workflow in action. In order to test the workflow add new item in announcements list. When we add a new item in list it will trigger the workflow to copy the item in CopiedAnnonucements list.

After adding new item in the Announcements list, you just have to refresh the page. Give 5 to 10 seconds to workflows to trigger and then refresh the page. You can see the item copied it the CopiedAnnonucements list.

Thats All, your workflow is ready and working what was expected.


SharePoint 2010 Release date announced

March 5th, 2010 Comments off

Yes finally SharePoint 2010 release date is announced. It is 12 May 2010 at 11:00 am. For more details Click here

Categories: SharePoint 2010 Tags:

Customization of SharePoint 2010 navigation – publishing site

February 12th, 2010 2 comments

In my previous blog, I customized the SharePoint 2010 publishing site. Now I will give you some idea that how you can create customize the navigation according to new look and feel. There are different ways to customize the navigation of SharePoint. I like to use a custom control which returns navigation in the form of xml and then I transform it from xsl. In this way you can easily control the output of the navigation or any other control.  

<SafeControl Assembly=SalmanSPControls, Version=, Culture=neutral, PublicKeyToken=49908bd985021621 Namespace=SalmanSPControls TypeName=* Safe=True />You need to add a reference in your SharePoint master page. It would be like this. 

<% @ Register Tagprefix=”SWC” Namespace=”SalmanSPControls” Assembly=”SalmanSPControls, Version=, Culture=neutral, PublicKeyToken=49908bd985021621″ %>  

Then I created a class for navigation inherited from ASP .Net Menu and xml based control class. This class is not doing much but just adding all the items in xml. It’s getting these items from Menu items. In the master page when you use this control you need to specify the data source id. If you search in your master page you can find a tag like this.  

<PublishingNavigation:PortalSiteMapDataSource EnableViewState=”false” ID=”leftNavDataSource” Runat=”server” SiteMapProvider=”CombinedNavSiteMapProvider” StartFromCurrentNode=”true” StartingNodeOffset=”1″ ShowStartingNode=”true” TreatStartingNodeAsCurrent=”true” TrimNonCurrentTypes=”Heading” />  

There will be two tags like above one for global navigation and other for current navigation. For left navigation you have to look the current navigation site map data source. In portal site map data source you can also change the SiteMapProvider, depending on your needs. You can use the current or combine or global. These site map providers are defined in web.config. You can find the difference of these site map providers in SharePoint documentation.
Now you have to replace the existing navigation control with your new custom navigation control. After that your master page changes are over. Now your control is ready and will display instead of default SharePoint current navigation. Here is how your navigation control will look like.  

<SWC:Navigation cacheperpage=”true” EnableViewstate=”false” ID=”LeftNav” Runat=”server” DataSourceID=”leftNavDataSource” Transform-XslName=”leftnav.xsl” Transform-CacheOutput=”false”/> 
But this control is just returning xml. You need to transform it in an html through some xsl. For this I created one xsl file and use some style classes to give it new look.  Here is the piece of code I use in my xsl to transform navigation xml into new look. 
<xsl:template match=”/>
    <xsl:if test=count(Navigation/Item) &gt; 0>
        <div id=nav-y>
                 <a href={Navigation/Item/@Url}title=”{Navigation/Item/@Title}>
                      <xsl:value-of select=”Navigation/Item/@Titledisable-output-escaping=”yes/>
                 <xsl:apply-templates select=”Navigation/Item>
                     <xsl:with-param name=”levelselect=”1/>
                     <xsl:with-param select=”@Titlename=”sectionTitle/>
<xsl:template match=”Item“>
    <xsl:param name=”level” />
    <xsl:param name=”sectionTitle” />
        <xsl:when test=”$level != 1“>
                <xsl:if test=”@Selected=’True’ or @Current=’True“>
                    <xsl:attribute name=”class“>Selected</xsl:attribute>
                <a href=”{@Url}title=”{@Title}“>
                    <xsl:value-of select=”@Titledisable-output-escaping=”yes“/>
                <xsl:if test=”count(Item) &gt; 0 and @Current = ‘True“>
                        <xsl:apply-templates select=”Item“>
                            <xsl:with-param name=”levelselect=”$level + 1” />
                            <xsl:with-param select=”@Titlename=”sectionTitle” />
            <xsl:apply-templates select=”Item“>
                <xsl:with-param name=”levelselect=”$level + 1” />
                <xsl:with-param select=”@Titlename=”sectionTitle” />
 So now after doing all these changes my new site will look like this.

Hope you enjoyed customization of SharePoint 2010 navigation in publishing sites.  


Branding of SharePoint 2010 publishing site

February 8th, 2010 Comments off

Couple of days ago, I was thinking to look the customization of new SharePoint 2010 publishing site. Here are the steps I took to achieve this goal. When you create a basic SharePoint publishing site, it looks like this.

As you people now that SharePoint websites are based on master-pages, and previously when we had to achieve branding in SharePoint 2007. We used minimal master page and then our own styling for it. I was thinking the same way that how I can get a minimal master page for SharePoint 2010. By the way if you look in the master pages library there is a master page named minimal.master. This page is a simple master page without navigation and much of the controls. It is a default master page for search pages. Anyhow the new term for minimal master page in SharePoint 2010 is starter page. Thanks to MSDN and Randy Drisgill, this starter page is available on CodePlex and MSDN. I picked the one from CodePlex and use the _starter.master. It is very well commented and easy to understand.

I have done the changes for html in master page for new look. For my style sheet I added a reference like this.

<SharePoint:CssRegistration name=“/Style Library/Styles/styles.css” After=“corev4.css” runat=“server”/>

If you want to do any change in the global (top) navigation or current (left) navigation you can do it from the SharePoint settings page. For this purpose you can select ‘Modify Navigation’ from the ‘Site Actions’ menu.

This is how it looks after the customization.

In next post I will talkabout creating custom controls for SharePoint 2010 publishing sites.

Develop, Deploy and Debug Sandboxed Solutions

December 18th, 2009 4 comments

Sandboxed solution in SharePoint 2010 is a new way of deployment for rapid development. You can deploy your solutions on site collections without resetting the farm. Sandboxed solutions are per site collection. You can create them like the normal farm solutions. You can see the detailed information about sandbox solutions here.

Develop SandBoxed Solution

 In Visual studio 2010 there is a lot of support for SharePoint projects. Whenever you start a new SharePoint project (except a few options) it will ask you about the solution type in second window. By default sandboxed solution is selected as solution type.

Select Deployment type

You can also change the deployment type at any time from the project properties window.

Change Solution Deployment type

In a SharePoint solution you can have assemblies, features, Web Parts, list definitions and feature receivers. Now if you want to add a Web Part in this solution, right click on the solution and select add new item.

Add new item

Select Web Part from the available option. In Sandboxed solutions you cannot use Visual Web Part. Actually from sandboxed solution you can deploy files to web front-end server. Visual web part deploys visual files to server. So you can use the simple Web Part from the option. If you select Visual Web part, you will notice that sandboxed solution option will be grayed-out in next screen, where you define deployment type.

Select Web Part

Now you can start writing your code for web part. I have added a snap-shot of sample code.


It’s a simple piece of code, accessing a list from the site collection and displaying items in a ListBox control. In sandboxed solutions you can access all the classes under SPSite, SPWeb, SPList, and SPListItem. Sandboxed solutions deploy as partial-trust solutions, so there are some limitations. You cannot use classes other than mention above. For example you cannot use code for run with elevated privileges block. If you try to use classes outside the scope of sandboxed solution you won’t get IntelliSense from Visual Studio. If use SPSecurity.RunWithElevatedPrivileges it will compile without any error message. It is because of the fact that visual studio compile against the full API of the SharePoint. Visual studio helps to write code specific for sandboxed solution by providing proper IntelliSense for available classes. But if you use code from a full-trust solution, there is no way to detect error in visual studio. You can only see exception when this code execute in sandboxed process. The exception thrown is “Could not load type ‘CodeToRunElevated’.

Use SPSecurity Error

When your build is successful, you can create a wsp file. In visual studio 2010, create a wsp is very simple. Previously it was another painful task to create wsp file. You had to use different ways to create a cab file and then rename it with extension wsp.  Now you can right click on the solution and select ‘Package’ option. It will create a wsp file for current solution in bin/Debug folder.

Create wsp solution
Deploy Sandboxed solutions
Deployment of sandboxed solution is very simple and rapid. You just have to upload your solution in a library name solutions. Every site collection in SharePoint 2010 has a solutions library. You can see more details about solution library here. Solutions library is a SharePoint list. When you upload your solution it will prompt to activate it.  If you like to upload a solution, better way to open the solution files in visual studio and then after the changes build and create a new solution. Now deactivate old solution from the solutions library and upload new solution. Finally activate it. Your solution is now deployed including the web part. Here you can also see that how you can use your custom web part in SharePoint pages. Click here

Debug Sandboxed solution
We know that SharePoint sites runs under the IIS worker process w3wp.exe. In order to debug SharePoint sites we attach our code to w3wp.exe process. But sandboxed solutions run under a different process Sandboxed worker process (SPUCWorkerProcess.exe).  so if you want to debug your code in sandbox solution you have to attach your code to SPUCWorkerProcess.exe and if you like to debug rest of the page then you have to attach it to w3wp.exe process.

Task manager view

I hope it will be helpful, I will try to explore more in coming days and will share again.