Posts Tagged ‘Salman Ghani’

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.

Retain the value of a dynamic control on post back

January 25th, 2010 14 comments

I heard this question several time that how you can retain the value of dynamically created controls on postbacks. You might see this before that when you create dynamic controls either in GridView or page. When you do postback, you cannot find the controls in page or GridView.

If you want your dynamic controls to work you can create them on page_load or page_init methods. But in some cases you have to create controls on some control event other than page_laod or page_init. In these cases you can follow my blog to retain the values of dynamic controls on postbacks.

In my case I have a button named btnSetParameters. On click event I’m creating controls in a GridView column. I have an ASP .Net panel in that column. My code is creating dynamic controls and then adding them to panel. But on postback I couldn’t found these controls in GridViewRow by their IDs. I need their values on postback.

For this I have created an ArrayList to keep controls.

Private objControlsList As New ArrayList

Then on RowDataBound where I was creating dynamic controls I added some code to add these controls in ArrayList. Here is an example of adding a TextBox in ArrayList. ASP Panel in GridViewRow name is pnlControls.

Dim txtValue As New TextBox
txtValue.ID = “txtValue1″
CType(e.Row.FindControl(“pnlControls”), Panel).Controls.Add(txtValue)

Do the same for all the dynamic controls and add them on ArrayList. You can even put custom controls in this ArrayList. After adding all the controls, put this ArrayList in Session.

Session.Add(“ControlsList”, objControlsList)

Now on page postback, use the controls from the ArrayList. Use the UniqueID to pick the values from the ViewState for orginal controls.

Dim txtSaved As TextBox = CType(objControlsTempList(counter), TextBox)
txtValue.Text = Request.Form(txtSaved.UniqueID).ToString()
counter += 1

For dynamic DropDownlist control you can use this piece of code.

Dim ddlSaved As DropDownList = CType(objControlsTempList(counter), DropDownList)
ddlSaved.SelectedValue = Request.Form(ddlSaved.UniqueID).ToString()
counter += 1

For radio buttons you can use this piece of code. You must define a group name while creating the radio buttons to use this code.

Dim rdSaved As RadioButton = CType(objControlsTempList(counter), RadioButton)
Dim radioName As String = (rdSaved.ClientID).Remove(rdSaved.ClientID.LastIndexOf(“_”)).Replace(“_”, “$”) + “$” + rdSaved.GroupName
If Request.Form(radioName) <> Nothing Then
        selectedValue = Request.Form(radioName).ToString()
End If

Now you can match this selectedValue with radio buttons in the Panels, to find the selected radio button.

For CheckBoxe controls you can use this code.

Dim chSaved As CheckBox = CType(objControlsTempList(counter), CheckBox)
If Request.Form(chSaved.UniqueID) <> Nothing Then
        chSaved.Checked = True
        chSaved.Checked = False
End If

Finally, you can use this code for dynamic custom control. It’s a bit tricky to find the value. I know the structure of my custom user control. It is a custom date control. It is actually creating two DropDownList controls for day and month part of date. And it is also creating a TextBox control for Year part of the date. Here is the piece of code I use to get the selected value of dynamic custom control on postback.

Dim dtSaved As CustomDate = CType(objControlsTempList(counter), CustomDate)
Dim cntlName As String = “”
Dim selectedDate As String = “”
cntlName = (dtSaved.ClientID + “_ddlDay”).Replace(“_”, “$”)
selectedDate = Request.Form(cntlName).ToString()

cntlName = (dtSaved.ClientID + “_ddlMonth”).Replace(“_”, “$”)
selectedDate += “/” + Request.Form(cntlName).ToString()

cntlName = (dtSaved.ClientID + “_txtYear”).Replace(“_”, “$”)
selectedDate += “/” + Request.Form(cntlName).ToString()

dateCtrl.DateValue = Date.Parse(selectedDate)
counter += 1

Hope it will help someone, creating dynamic controls and retain the values on postbacks.


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.

Solutions Library – SharePoint 2010

December 17th, 2009 53 comments

One of the salient features in SharePoint 2010 is sandboxed solution. You can see the detailed introduction to sandboxed solutions in my other blog. Every site collection in SharePoint 2010 has a library with name Solutions. You can upload your sandboxed solutions in this library. This is a simple SharePoint list. In order to access it you have to open site settings page. You can select Site Settings option from site actions menu.
From site settings page, there is a link for Solutions library under Galleries section.Site Settings Page

Solution library displays the list of solutions, their status and the resource usage as well. It also displays resource quota information for server resources, also current usage and average usage. You can also activate and deactivate solutions. In solutions library you can upload your solutions. For this you can select upload solution option from the ribbon.

Solutions Library

When you click on upload solution, it will open a window like this.

Upload Solution

This window is saying upload document, I don’t know why. May be it’s just a beta version. It should say upload solution, and solution file could be pre-selected in file type filter. You can browse your solution (wsp) file. You can activate the solution straight away after the upload or at any other time.

Activate Solution

You can remove any solution from the library. But this solution should be deactivated first. You can also upgrade any solution but the condition is same, it should be deactivated first. In order to upgrade the solution your solution id should be the same. Whenever you upgrade a solution, it will deactivate the old version and activate the new version.  If you try to upgrade any activated solution, you will see error windows like this.

Upload same solution - Error

In solutions library, you can upload any type of file. But the ribbon is context sensitive. Activate, Deactivate and upgrade buttons could be enabled only for wsp files.
I hope it will be informative about solutions library.

Create WebPart page and use custom WebParts – SharePoint 2010

December 16th, 2009 Comments off

This topic is probably for new users of SharePoint. It is a very simple task for old SharePoint users to create a web part page and use a custom web part. In this topic we will see step by step that how we can create a web part page in a publishing site using SharePoint 2010, and how we can use web parts in the page.
There are two straight forward ways to create a web part page in publishing site. First you can click on site actions menu and then select New Page option from there.

New Page

When you click on New Page option, it will open an AJAX window, where you can define the name of page.

Create New Page - Name

It will create a basic page. From the ribbon you can select Page Layout option. It will open a drop down to select page layouts from the existing layout types. You can select Blank Web Part page from here. It will change the page layout to blank web part page layout. You can also create your custom page layouts and can use here to create new pages.

Select WebPart page layout

Second way to create a web part page is to select ‘site actions’ and then select view all site content. Then select the create option, it will open different items to create like custom list, different page types, libraries. From there you can select web part page.

Create options window

Or you can also select page in filter by option. And then can select web part page. All the above options will create the same web part page.

Create - Filter by Page

On this layout there are different web part zones, where you can place your web parts. When you select Add a web part from any available zone, it will open the list of available web parts in different categories on top of the page. First option is for list and libraries. Here you can see all the existing list and libraries.

Select list in webpart

For the header zone I have selected an existing list Regions as a web part. It will look like this.

List view in web part

Now if you have created your own web part and added through some solution to the web application, then you can also use your custom web part in this page. For this click on Add Web Part option and then select the custom category for web parts. From here you can select your existing web parts for the page.

Select Custom webpart for page

It is a very basic option but hope it will help to the new users of SharePoint.

Have Fun.

Sandboxed Solutions in SharePoint 2010

December 14th, 2009 2 comments

SharePoint 2010 came with lots of new features and ways for developers and users. Sandboxed solution is one new way of deploying solutions. You can also have the solutions as you have in SharePoint 2007, but those solutions will be called farm solutions. Sandboxed solution is per site collection. Sandboxed solution’s deployment is different than normal solutions. Every site collection in SharePoint 2010 has a library for sandbox solutions. You simply need to upload your solution (wsp) to this library. And then activate the solution. So no server reset is required.
Sandboxed solution doesn’t make server reset, so you can do as much deployments as you want. It is very convenient from developer’s point of view. But at the same time there are some limitations for sandboxed solutions. Farm solutions run with full trust, whereas sandbox solutions mark as partially trusted solution. The major difference is the way of deployment. You can run the same solution under full-trust, but then you need to deploy it as a farm solution. As you do in SharePoint 2007.
The limitations for the sandboxed solution is due to the factor that it should not be a performance hinder for farm and application. These are the major limitations I found so far in sandboxed solutions.

  • You cannot run your code with elevated permissions in sandboxed solution
  • You cannot use Visual web part template for sandboxed solution. Because sandbox solution cannot deploy files to web front end.
  • You cannot access internet to make web service calls directly
  • You cannot access hard drive to read/write files
  • you can’t access code that is not marked to allow partially trusted callers
  • you cannot deploy assemblies to GAC

It seems that in sandboxed solutions’ you cannot do much but still you can. In sandbox solution you can access all the classes under SPSite, SPWeb, SPList, and SPListItem. You can create Web Parts, list definitions and instances, content types and fields, modules, declarative workflows, and event receivers. You can read and write to lists and libraries within same site collection. Sandboxed solutions provide enough functionality to build most of the applications. The best thing is rapid deployment and no server reset.
Being a developer you would definitely want to go out of the limited scope of sandboxed solutions, like communicate with a database or web service. According to SharePoint team the best way to reach out of the sandbox is by using the Business Connectivity Services (BCS) to create an external content type. You can then read and write to the data source from the sandboxed solution. Another, more advanced, way to reach outside the sandbox is to create a class that runs in a full-trust process outside the sandboxed worker process to proxy calls. This proxy class is deployed as a farm solution and is callable from the sandboxed solution.
Sandboxed solution runs under a different process, farm solutions run under IIS worker process (w3wp.exe). But sandboxed solution runs under the sandbox worker process SPUCWorkerProcess.exe.
In sandboxed solutions library, you can activate and deactivate solutions. You can also remove solution from the library, but solution should be in deactivated state. You can also upgrade a sandboxed solution. To upgrade a solution, you need to create a .wsp file that has a new file name but the same solution ID. The easiest way is to use Visual Studio 2010 for it. Open the same solution and after the changes, give the package a new name using package designer. When you try to upload new solution, it will detect the solution with same id and ask for upgrade. After you upgrade, you will see it activated new version and deactivated old solution.

Sandboxed solution is a great enhancement for developers and also for administrators. Now all the solutions deployment is not the responsibility of the farm administrators. Site collection administrator can deploy, manage and monitor sandboxed solutions for their site collections. Developers can test functionality without disturbing the whole farm. They can deploy the same solution with full trust later, when they have confidence in the new functionality or at convenient time. Isn’t that a great news.


Issues notification from Health Analyzer – SharePoint 2010

December 3rd, 2009 Comments off

In my previous post I discussed something about Health analyzer in SharePoint 2010. When health analyzer finds some issues against the pre-defined rules. It shows notifications on the Central Admin screen. This notification bar will look like this. If there is any error then this bar color will be Red, if these are just warnings then it will be yellow.

Red Notification for errors

Errors notification in red bar.

Yellow Notification for warnings

Warnings notification in yellow bar.

When you click on view these issues, it will take you to the health report page. From there you can see the details of each issue and can edit the item as well. If you think that these issues are coming against unnecessary problem. Then you can also change the rule definitions by disabling or removing it from the Health Analyzer list. For this you can read my previous post about Health Analyzer.
There could be unnecessary issue notifications, like I’m running SharePoint 2010 on my hp laptop and it was giving me low disk space error for recovery disk. So I just remove this error from the list.

Health Report

And here you can see the screenshot of the details page when you click on any of the issue. If you think you have fixed the issue, then you can reanalyze it as well to remove this error from this report. 

Review problems and solutions

Here you can also change the severity of the item. It will give you all the details about the issue, server name where this issue occurred. It will also tell you failing service and some description for the item. Now you may like to remove this from rule definition. On this screen you can see the category name and then you can find this rule from the rule definitions list under this category. The interest section is remedy, where it will gives you some idea about the problem and solution for it. Isn’t that amazing thing from Microsoft?

Have fun.

Health Analyzer in SharePoint 2010

December 3rd, 2009 Comments off

One of the amazing features in SharePoint 2010 is Health analyzer. Health analyzer is working through the timer jobs and collect data from these jobs. This data is saved in logging database and logging folder. These health analyzing jobs are configurable. You can reschedule, enable, disable, or run immediately.
By default these jobs are running against some pre-defined rules. These rules are in belongs to different categories like Security, Performance, Configuration, and Availability. If you go in Central Administration and click on Monitoring.


 On monitoring page there are two options under Health Analyzer section. ‘Review problems and solutions’ is to take you to a page displaying all the current issues and ‘Review Rule definitions’ will open the page with existing rules.
On this page you can see that when these rules are schedule to analyze, enabled or disabled, and if repair automatically is selected or not. From this screen you can also remove any existing rules.

Health Analyzer Rule Definitions

When you click on any item it open a dialog window with the properties of the rule. On this dialog you can change settings for selected rule.
Selected Rule

Here you can change the Scope for rule. In Scope you define the server to run the timer job. It could be just one server or can be set to ‘All Servers’ in farm. Then you can change the schedule for rule. Then you can enable or disable the rule and also can set the property for Repair Automatically. If you set this property to yes, then SharePoint 2010 will try to resolve the problem for you. I don’t really know that SharePoint 2010 can resolve all the problems. But you can give it a try for basic things. As we have these rule definitions as a SharePoint list, so version is actually telling the version of the list item.

Create New web application in SharePoint 2010 – Part 2

December 2nd, 2009 Comments off

Continue from part – 1, if we want to use windows authentication we can select this option on this part of screen. SharePoint team recommends Negotiate (Kerberos or NTLM). If you want to enable form base authentication then you can select the option to enable ASP .Net Membership and Role Provider.

Configure Authentication

If you are using ‘Custom Based Authentication’ you can define a custom login page. You need to give the url of login. Public URL part is same as SharePoint 2007. You can extend your web application later for other zones. For example if you want to extend your site for internet access, you can extend your site using internet zone.

Configure URL

In this section you can configure application pool and security account for application pool. If you are creating first application or if you have not registered any managed account. Then before using configurable account you need to register managed account from the given link. In my case this is the first web application, so I will register a managed account.

Configure Application Pool

Next section is the same as in SharePoint 2007 to configure content database.

Configure Database

Now there is a new option for failover database support. You can find more details here (Failover Database Support).

In next screen you can add remove service application connections for your web application.

Service Application Connections

Now in SharePoint 2010, services concept has been shifted from Share Services Provider (SSP) to the service application. You can read this article from Andrew Connell for more details. By default all web applications are associated with the farm’s Default group of service application connections, although you can change this setting. Here you can see my article that how you can create a custom set of service application connections.

Now the last section is about Costumer Experience Improvement Program.

Customer Experience Improvement Program

This is the optional field. If you opt-in to the Customer Experience improvement Program, anonymous data about how you use SharePoint 2010 are uploaded to Microsoft occasionally in the background.