Friday, March 25, 2011

Custom 404 Page not found error page - SharePoint

SharePoint is a content management system, so people creates thousands of pages and at the same time deletes hundreds or thousands of pages, if you hit one of page in deleted pages then you will get page not found error (blue and white screen page), but the problem is the error page is not user friendly, you will not find any redirection link, so how will you solve this problem?

Usually, we apply 404 page at IIS virtual directory level, but how will you apply same for SharePoint website?

In SharePoint when we create web application using SharePoint central administration internally that will create a virtual directory under IIS, so now our job is so easy, just check below code, the SPWebApplication refers to Virtual Directory

Create a feature receiver and add below code in to FeatureActivated method

See, the web application class contains a property called “FileNotFoundPage” just apply your custom 404 page to that property

SPSite curSiteColl = properties.Feature.Parent as SPSite;
System.Uri webApplicationUri = new Uri(curSiteColl.Url);
SPWebApplication webApplication = SPWebApplication.Lookup(webApplicationUri);
webApplication.FileNotFoundPage = "404ErrorPage.html";
webApplication.Update();

The property accepts only HTML page, so we need to assign HTML page and then using Java script redirect to our custom .aspx page

<html>
<head>
<meta HTTP-EQUIV="Content-Type" content="text/html; charset=utf-8" />
<meta HTTP-EQUIV="Expires" content="0" />
<script language="javascript" src="/_layouts/1033/init.js"></script>
<script language="javascript" src="/_layouts/1033/core.js"></script>
<script language="javascript">
var requestedUrl = escapeProperly(window.location.href);
STSNavigate("/_layouts/ErrorPages/404ErrorPage.aspx?oldUrl=" + requestedUrl);
</script>
</head>
<body>
</body>
</html>

Now, open the 404ErrorPage.aspx page and add whatever message you want under place holder main section

<asp:Content ID="mainContent" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<table>
<tr>
<td class="ErrorPageTitle" >
<span class="ErrorPageTitle1">Page Not Found</span>
</td>

</tr>
<tr>
<td> <span class="ErrorPageMsg1">The page you requested could not be found. Use this link<http://mspbox.blogspot.com> to redirect to home page </td>
</tr>
</table>
</asp:Content>

Thursday, February 24, 2011

Custom error message in SharePoint 2010 + Feature Receiver

In SharePoint 2007 there was no way to redirect to custom error page when you use event receivers, if you try also it redirects to default out of the box blue-white error page

But in SharePoint 2010 there are some properties by using this you can redirect to custom error page

public override void ItemAdding(SPItemEventProperties properties)

{
base.ItemAdding(properties);
string tite = properties.AfterProperties[“title”].ToString();
if(tite.Contains(“RSM”))
{
properties.Cancel = true;
properties.Status = SPEventRecieverStatus.CancelWithRedirectUrl;
Properties.RedirectUrl = “/_layouts/CustomError.aspx?errormessage=bang...don't use RSM...I hate RSM”;
}
}

Limitations.

This works only for synchorounous events like Itemadding, deleting etc...
Works only for browser based clients not with outlook.

Tuesday, February 15, 2011

Language pack probem Spanish(United States)

Today, we started developing new locale for our existing site that is Hispanic locale for United States, but the main problem which we found is Microsoft does not provide language pack for Hispanic (United States) the solution for this we have chosen (Spanish) Mexico language pack (es-MX)under regional settings of site collection settings of site because the Spanish (Mexico) and Spanish (United States) are almost same

But, before start developing new locale with above approach the resource files should be in the form of .es-MX.resx not .es-US.resx because you have chosen (Spanish)Mexico language pack (es-MX) under regional settings of site collection

Tuesday, February 1, 2011

Planning Content Type Hubs in SP2010

when you are developing enterprise application for large organization some fields are common across all brands such as brand name, brand logo, SEO title, SEO description etc..

How will you handle this common fields across farms?

Scenario (P&G only for reference)

Assume that we are designing architecture for P&G products, normally P&G has lot of products (Pantene, Olay, pampers etc...)but, all these products have some common fields such as Product logo, product name, SEO title, SEO description etc... How will you handle this?

SharePoint 2007

In SharePoint 2007 usually what we do? we go and create separate content type for this called brand content type and deploy this into site collection but, here the problem is we need to go to each and every web application and install site content type feature , there is no central location to place common fields, in future if you want to update particular column, you have to go to each and every web application and update

SharePoint 2010

In SharePoint 2010 there is a new concept called Content Type Hubs, through this you can manage all common fields centrally and publish it to the other web applications, so in 2010 the other web applications can subscribe these content types and pull down the published content types from the CTH and also can get updates when ever changes happened in published content types

Here, mainly you need to concentrate on three things

Site collection to host the content types and act as a Content Type Hubs

Managed metadata service application( to expose content type hub to each and every web application)

Web applications ( to subscribe content type hubs)

Advantages

No need of going to each and every web application and installing the content types and if you want to do updates on particular content type you can simply do it on Content Type Hubs and push it down, so managing the content types easy

In reality the content types changes frequently like adding new fields or creating new content type etc... It's easier to coordinate this from a single location and make sure that xml files are correctly set up across all web applications/farms.

Tuesday, January 18, 2011

Moving data from one site collection to other and make it up

In SharePoint, we need to concentrate on lot of things while moving site from one environment to another environment and make it up

Based on my experience, I am sharing some of the details with you guys

If you are using VSIDE to develop your site for example creating custom web parts, master pages, css files, features etc...and then developed using VSIDE Then WSP package is best solution but this will solve only half portion of your requirement that means you are deploying static content means the data which will not change frequently

But, you need to think about how the dynamic data will be deployed from one environment to another environment dynamic content means the content which is authored by client like new article page, new documents uploaded into document library etc...

here you need to use either content deployment or Export /Import but in my SharePoint journey I have used both, choosing the right option is depends on how our environment is setup?

If your environment is farm environment and having multiple nodes with reliability and security then we can use content deployment option because content deployment will transfer the data on wire so, make sure that there should not be any connection failure while doing content deployment

Before doing content deployment you need to consider lot of things

1. The source farm and destination farm should be identical, assume that you have installed latest service pack or language packs on source farm and the same is not available on destination farm then this will give problem and the content deployment will fail.

2. The destination site collection should be blank site collection if not then the job will fail because when The first time the content deployment job runs, the correct template and all associated configuration settings will be applied to the destination server if site collection already contains data then the job will fail.

3. The disk space in source and destination farm should be enough otherwise disk allocation problem will occur because when job starts it will create a cab file in source temporary folder and export into destination farm temporary folder.

4. if you have any custom features to install in destination server just install before running your job but don't activate the features because if you activate that will create data in content database so, this may lead to content deployment fail.

5. Don't run the content job's parallel this may lead to content job fail.

Normally SharePoint enterprise application will have two farm topology authoring and production farm. Authoring farm works on AD and production is internet facing site and works on FBA, the content authors will upload the data into authoring site and the same will be available in production site through content deployment. There is no specific requirement to have only two farm topology, based on requirements you can build multi-farm,I worked for one client who is having five farm topology

I suggest to use content deployment because you can do differential content deployment that means whatever changes made recently will be only moved to one environment to another environment so, this will not override existing content