Monday, October 17, 2011

Alternate accessing mapping issue over internet

SharePoint is quite interesting in terms of its own features, Customization, deployment and disaster recovery. It provides good feature to add different URLs for different zones and allows extending the web application. These feature ultimately reduces the work effort of System/SharePoint Administrators and time as well. At the same time SharePoint needs some basic security configuration to perform all operation successfully. Here I would like to explain the issue and how it was resolved.

I have created a web application and added a custom managed path. The managed path type is explicit(Don’t allow to create more than a instance under this path). Then created a top level site collection under this managed path. The SharePoint portal has been published in the location network and it was working fine. After few day our customer wants to publish the SharePoint portal over internet. For public URL I have taken help from our network/IIS team to create and register the public URL. Finally I got the URL for our SharePoint portal(eg. I have added the public url in the custom zone and done below settings/configuration.
1. Update the host file(:\WINDOWS\system32\drivers\etc) with new host header
2. Updated the virtual directory bindings with new URL and points the default port i.e. 80.
After completing the Alternate access map settings the portal was accessible in the server. Over internet only the portal landing page(Home page) accessible but not any other Site objects (sub sites, document library..) for following reason (1. Custom managed path, 2. Site Redirection). The site objects url not been transferred as expected. Those urls points to the server IP address and port instead public url. Then I realized that the problem in the firewall setting since the Portal is working in the server but not over internet.

Error e.g.
Over internet:

Sub site URL:
Folder URL : http://

In SharePoint server:
Sub site URL:
Folder URL :
Solution :
To rectify this issue I asked ISA expert to verify the ISA setting in the server. Our ISA expert diverted the request from “” to “”. This solved our first issue.
Then we came across another problems
Issue 1:
Some of the url special characters as encoded twice in the URL. So the SharePoint object were not able access over internet.
I have searched for solution over internet then got that “verify normalization” has to be disabled in the server. Our ISA responsible did the changes as requires.
Actually, in this case 'verify normalization' has to be disabling in the server. When the option verifies normalization is enabled, the ISA firewall will escape the URL, then escape it once more. If the second escape attempt results in a string that is different from the first string, the ISA firewall will object and deny the traffic.
Issue 2:
Finally we got another issue that “List operation(Create, Update, delete) not able to perform”. Therefore during the data modulation in the list user gets 500 server internal error and the operation goes incomplete.
Error description:
Page: 500 Server internal error. The space character in the URL has encoded twice. For e.g. (http://sitecoll/lists/test%2520/displayform.aspx?ID=10). The Space(%20) has encoded twice there the url has %2520
Solution2 :
There was some issue with WebResource.axd. It was not allowed from external. Then ISA responsible did the settings to allow WebResource.axd from external.
Now our site works as expected.
Happy working with SharePoint issues.

Wednesday, September 21, 2011

Add a custom webpart to a SharePoint site/page

I came across the situation like need to add more than a custom webpart on the landing page of my SharePoint site when creating a new site collection or sub site using custom site definition. Of course the answer will be "Yes, You can add the webpart in the onet.xml file" But the question is Will onet.xml file allow user to add more than a webpart in it?

<AllUsersWebPart WebPartOrder="1" WebPartZoneID="Right">
<webParts> <webPart><data><properties>
Custom webpart property details

If you try adding more than a webpart in onet.xml file the throws flowing error.

Error: Web Part Error: Invalid Web Part tag.

Show Error Details

Error Details

[WebPartPageUserException: Invalid Web Part tag.]
at Microsoft.SharePoint.WebPartPages.WebPartImporter.ProcessNodes(ProcessNode fixupNode, String xpath, Boolean deleteProcessedNodes)
at Microsoft.SharePoint.WebPartPages.WebPartImporter..ctor(SPWebPartManager manager, XmlReader reader, Uri webPartPageUri, SPWeb spWeb)
at Microsoft.SharePoint.WebPartPages.WebPartImporter.Import(SPWebPartManager manager, XmlReader reader, Boolean clearConnections, Uri webPartPageUri, SPWeb spWeb)
at Microsoft.SharePoint.WebPartPages.SPWebPartManager.CompressWebPartNoSave(Boolean isClosed)

So the another way of adding webpart on the site is via Feature stapler or directly by activating the feature. If the webpart want to be placed by default when the site created then the preferred choice is feature stapler. If user wants to add the webpart on need basis then go for activating feature.

Feature that add the webpart on the SharePoint site.

1. Assume that the custom/required webpart is available in the webpart gallery
2. Create the empty SharePoint 2010 project in visual studio 2010.
3. Add a new Feature in the project name as your wish(e.g "MyCustom webpart Feature" and GUID is "7bf8afb6-57dd-408d-b7c5-fea4b861b3cc")
4. Make the feature scope to web level
5. Add the Event receiver to the Feature
6. Add the System.Web.dll in the Refernces
7. Add below name spaces

using System;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Web.UI.WebControls.WebParts;
using System.Xml;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;
8. Use below source code to add the webpart on the site.

public override void FeatureActivated(SPFeatureReceiverProperties properties)
using (SPWeb currentWeb = (SPWeb)properties.Feature.Parent)
using (SPLimitedWebPartManager webPartMgr = currentWeb.GetLimitedWebPartManager("default.aspx", PersonalizationScope.Shared))
using (System.Web.UI.WebControls.WebParts.WebPart webPart = CreateWebPart(currentWeb, "MyCustom.webpart", webPartMgr))
webPart.Height = 300;
webPart.Width = 300;
webPartMgr.AddWebPart(webPart, "Right", 1);
catch (Exception ex)
throw ex;

public static System.Web.UI.WebControls.WebParts.WebPart CreateWebPart(SPWeb web, string webPartName, SPLimitedWebPartManager manager)
SPQuery query = new SPQuery();
query.Query = String.Format(CultureInfo.CurrentCulture, "<Where><Eq><FieldRef Name='FileLeafRef'/><Value Type='File'>{0}</Value></Eq></Where>", webPartName);
SPList webPartGallery = null;
if (null == web.ParentWeb)
webPartGallery = web.GetCatalog(SPListTemplateType.WebPartCatalog);
webPartGallery = web.Site.RootWeb.GetCatalog(SPListTemplateType.WebPartCatalog);
SPListItemCollection webParts = webPartGallery.GetItems(query);

if (webParts.Count > 0)
XmlReader xmlReader = new XmlTextReader(webParts[0].File.OpenBinaryStream());
string errorMessage;
System.Web.UI.WebControls.WebParts.WebPart webPart = manager.ImportWebPart(xmlReader, out errorMessage);
return webPart;
else { return null; }

9. Buid and deploy the solution

Note: Parameters for GetLimitedWebPartManager("default.aspx", PersonalizationScope.Shared) relative url and personalization scope. The relative url should your target page url. In above example used "default.aspx" where the Wiki Page Home Page feature deactivated. For default wiki page it may be "SitePages/Home.aspx".

"MyCustom.webpart" is name of the webpart that you want to add in the home page.

Need to create a stapler feature To attached with any site template.

1. Add a another feature to the project/solution
2. Add the empty element file to the feature
3. Add below tag with correct feature GUID of "MyCustom webpart Feature" in the element file

<FeatureSiteTemplateAssociation Id="7bf8afb6-57dd-408d-b7c5-fea4b861b3cc" TemplateName="

Wednesday, September 14, 2011

List Item URL (Edit- Link to Item) using CAML query

The method SP.UI.ModalDialog.showModalDialog can be used for opening list item in model dialog. It requires target URL as input parameter.

<a href="{$hyperLink}" title="{$TaskTitle}" >
<xsl:attribute name="onclick">
SP.UI.ModalDialog.showModalDialog({url:'<xsl:value-of select="$hyperLink"/>' });return false;
<xsl:value-of select="$TaskTitle"/>

Below is the complete example. The xml data generated from task list.



<Title>test123 task</Title>
<Status>Not Started</Status>
<Title>PMO Task01</Title>
<Status>Not Started</Status>
<Status>Not Started</Status>


<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl=""
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
<xsl:output method="xml" indent="yes"/>
<xsl:variable name="hyperLink"/>
<xsl:variable name="baseurl"/>
<xsl:variable name="TaskTitle" />
<xsl:key name="proj" match="PMOProject" use="node()[name()='ProjectProperty.Title']" />
<xsl:template match="NewDataSet">
<xsl:for-each select="PMOProject[count(. | key('proj', node()[name()='ProjectProperty.Title'])[1]) = 1]">
<xsl:sort select="node()[name()='ProjectProperty.Title']" />
<xsl:value-of select="node()[name()='ProjectProperty.Title']" />
<br />
<xsl:for-each select="key('proj', node()[name()='ProjectProperty.Title'])">
<xsl:sort select="node()[name()='Status']" />
<xsl:variable name="TaskTitle" select="node()[name()='Title']" />
<xsl:variable name="baseurl" select="substring-before(node()[name()='FileDirRef'],'Lists/')"/>
<xsl:value-of select="node()[name()='Status']" /> <xsl:variable name="hyperLink" select="concat(node()[name()='EncodedAbsUrl'],substring-after($baseurl,'#'),'Lists/ProjectPlan/editform.aspx?ID=',node()[name()='ID'])"/>:-
<a href="{$hyperLink}" title="{$TaskTitle}" >
<xsl:attribute name="onclick">
SP.UI.ModalDialog.showModalDialog({url:'<xsl:value-of select="$hyperLink"/>' });return false;
<xsl:value-of select="$TaskTitle"/>
</a><br />

Wednesday, September 7, 2011

Find the SharePoint web Template ID

The web template id can be found using object model or Power shell script.
Powershell script to find the specific web template details:
Open windows Powershell ISE to execute the comments/scripts. Load the SharePoint assembly if those are not loaded.
To load the SharePoint assembly
[System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c")
This assembly can be referred using the “LoadWithPartialName” function which doesn’t require the full assembly information:

$web = Get-SPWeb http://portal
write-host "Web Template:" $web.WebTemplate " Web Template ID:" $web.WebTemplateId
Above script can be stored as a .ps1 file and can be executed using SharePoint PowerShell window.

C# code to find out the web template details:
Server Object model can be used for finding out the web template details.
using System;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
namespace ConsoleApplication1
class Program
static void Main(string[] args)
using(SPSite site=new SPSite(@"http://sitecoll/"))
SPWeb web = site.RootWeb;
Console.WriteLine("Web Name : "+web.Title);
Console.WriteLine("Web Template Name : " + web.WebTemplate);
Console.WriteLine("Web Template ID : " + web.WebTemplateId);
Console.WriteLine("Web GUID : " + web.ID);
catch (Exception ex)
Console.WriteLine("Error: "+ex.Message);

Tuesday, September 6, 2011

Tips on Blank site Template

The Blank site template is somewhat defferent from other site templates in SharePoint 2010.

Taxonomy will not work in Blank site template since the feature is not activate. User has to activate the feature manually. The Taxonomy Feature Stapler attached with global and some of site templates but not with blank site template. The attribute AllowGlobalFeatureAssociations=”False” in blank site template.

To activate Taxonomy Feature using Power Shell

Enable-SPFeature -identity “73EF14B1-13A9-416b-A9B5-ECECA2B0604C” -url “http://sitecollection/”
Enable-SPFeature -identity “TaxonomyFieldAdded“ -url “http://sitecollection/”

To activate Taxonomy Feature using STSADM command

STSADM -o activatefeature -id “73EF14B1-13A9-416b-A9B5-ECECA2B0604C” -url “http://sitecollection/” –force
stsadm -o activatefeature name TaxonomyFieldAdded -url “http://sitecollection/”

Monday, July 25, 2011

Activate Publishing Feature in SharePoint

Feature Stappling is one of the gratest feature in SharePoint. It is easiest way of attaching a feature with existing site definitions without disturbing existing template. This feature will work like plug and play concept. Therefore the features can be attached and enabled by default for any site templates. For example activate the Publishing feature when a Blank site created. This feature has two features one is “Stappler” feature which is used for attaching another feature to the site definition. The another one is “Staplee” feature which get attached with site definition. We have a simple feature stappling demo now.

Requirement: Publishing site Feature has to be enabled when a Team Site created in the Site Collection.


1. Create a stapler feature and name it as “ActivatePublishingFeature”

2. Find the Staplee Feature GUID because the publishing feature is already deployed in the Farm. In case custom feature, need to use that Feature’s GUID

3. Install the Feature

4. Activate the feature.


xml version="1.0" encoding="utf-8"?>

<Feature xmlns="" Title="ActivatePublishingFeature " Id="f7ff397a-65f1-4e82-ad7d-c75111bceef6" Scope="Farm">


<ElementManifest Location="SitePublishingFeatureElement\Elements.xml" />




xml version="1.0" encoding="utf-8"?>

<Elements xmlns="">

<FeatureSiteTemplateAssociation Id="94C94CA6-B32F-4DA9-A9E3-1F3D343D7ECB" TemplateName="STS#0" />


Refer this link to get the GUID of SharePoint 2010 default features.

Refer this link to get the SharePoint 2010 default web templates list

SharePoint 2010 Default web templates

SharePoint 2010 has many number of predefined site templates. A single template will be used at the time of creating a new site. New site can be created using SharePoint user interface or using Object Model (C# or VB) or PowerShell Script. The template details should be specified at the time of creating the site using Object Mode and PowerShell Script.

Predefined template IDs can be fetched using PowerShell Command " Get-SPWebTemplate"

Object model Syntax for creating new sub site

public SPWeb Add(
string strWebUrl,
string strTitle,
string strDescription,
uint nLCID,
SPWebTemplate WebTemplate,
bool useUniquePermissions,
bool bConvertIfThere

List of Web Templates

Template ID Template Name
GLOBAL#0 Global template
STS#0 Team Site
STS#1 Blank Site
STS#2 Document Workspace
MPS#0 Basic Meeting Workspace
MPS#1 Blank Meeting Workspace
MPS#2 Decision Meeting Workspace
MPS#3 Social Meeting Workspace
MPS#4 Multipage Meeting Workspace
CENTRALADMIN#0 Central Admin Site
WIKI#0 Wiki Site
BLOG#0 Blog
SGS#0 Group Work Site
TENANTADMIN#0 Tenant Admin Site
ACCSRV#0 Access Services Site
ACCSRV#1 Assets Web Database
ACCSRV#3 Charitable Contributions Web Database
ACCSRV#4 Contacts Web Database
ACCSRV#6 Issues Web Database
ACCSRV#5 Projects Web Database
BDR#0 Document Center
OFFILE#0 (obsolete) Records Center
OFFILE#1 Records Center
OSRV#0 Shared Services Administration Site
PPSMASite#0 PerformancePoint
BICenterSite#0 Business Intelligence Center
SPS#0 SharePoint Portal Server Site
SPSPERS#0 SharePoint Portal Server Personal Space
SPSMSITE#0 Personalization Site
SPSTOC#0 Contents area Template
SPSTOPIC#0 Topic area template
SPSNEWS#0 News Site
CMSPUBLISHING#0 Publishing Site
BLANKINTERNET#0 Publishing Site
BLANKINTERNET#1 Press Releases Site
BLANKINTERNET#2 Publishing Site with Workflow
SPSNHOME#0 News Site
SPSSITES#0 Site Directory
SPSCOMMU#0 Community area template
SPSPORTAL#0 Collaboration Portal
SRCHCEN#0 Enterprise Search Center
PROFILES#0 Profiles
BLANKINTERNETCONT... Publishing Portal
ENTERWIKI#0 Enterprise Wiki
SRCHCENTERLITE#0 Basic Search Center
SRCHCENTERLITE#1 Basic Search Center
visprus#0 Visio Process Repository

Wednesday, May 25, 2011

The specified file is larger than the maximum supported file size

This error occurs when user upload a file that size exceeding than the allowed limit. Normally SharePoint library allows only 50MB as default upload file size. If user wants to upload file that size more than 50 MB, the upload file size limit has to be increased in the Central Administration by Administrator.

Open the SharePoint2010 Central Administration. Click on Manage web application link which us under Application management section.

Select the web application that needs update on file upload size.

Navigate the General setting in the ribbon control for selected web application. Then click on General setting.

Now update the size in the maximum upload size input text box. And then click on Ok button. Note: The value for maximum upload size is invalid or out of range. The maximum value is 2047 MB

Wednesday, May 18, 2011

Office 2010 Product Guides

Microsoft has prepared good product guides for Office 2010 applications. It is very useful for Office 2010 beginners. Refer below URL to get all Office 2010 product guides.

Tuesday, May 17, 2011

How to Hide Quick Launch in SharePoint 2010

The easiest way to hide the quick launch bar in a specific site/subsite is simple Style script/code.
1. Open the SharePoint site and switch to Edit Mode
2. Add the HTML Form Web Part from Forms webpart group
3. Select the web part and click “Edit HTML source” in Editor part
4. Use below code and click on Apply -- OK button

Configuration Failed when installing SP 2010 on Windows 7

I found a very useful link that guides to solve most of the SharePoint 2010 installation issues on Windows 7 machine.

Friday, April 22, 2011

Find Users and Groups for Group Owner

SharePoint treat the domain group as a user. A new entry will be created in the userinfo list(hidden list) as soons as a new domain group added in sharepoint site collection or in the sub site directly. This entry will be created only one time for site collection. The userinfo list view accessable by passing _catelogs/users/simple.aspx in the URL (http://sitecollection:8080/_catelogs/user.simple.aspx).
In SharePoint SPGroup or Domain group can become a owner of another group in SharePoint(SPGroup and Domain Group). To find out the Onwed groups of a SPgroup or Domain Group use below source.

static void Main(string[] args)
using (SPSite siteColl = new SPSite("http://sitecollection/"))

//For nested SharePoint groups

SPGroupCollection groups = siteColl.RootWeb.Groups;

foreach (SPGroup group in groups)

if(group.Owner.ToString()=="GroupA" )
Console.WriteLine("\nGroup Name: " + group.Name + " Group Type: " + group.LoginName);

//For nested domain groups
SPUser usr=siteColl.RootWeb.AllUsers["domain\groupName"];

foreach (SPGroup domainGroup in usr.OwnedGroups)
Console.WriteLine("\nGroup Name: " + domainGroup.Name + " Group Type: " + domainGroup.LoginName);

catch (Exception ex)
Console.WriteLine("Error :"+ex.Message);