Showing posts with label SharePoint Publishing. Show all posts
Showing posts with label SharePoint Publishing. Show all posts

Sunday, August 1, 2010

Duplicate name error while creating SharePoint publishing page instance

Most of the time you would always find some or the other issues while deploying your solution components from dev environment to any other environment like authoring or staging.

A couple of days before, we encountered one such issue while creating page instances using our custom content types on authoring environment. The error we encountered was

A duplicate name “YOUR CONTENT TYPE NAME” was found. at Microsoft.SharePoint.Publishing.Internal.Codebehind.CreatePagePage.HandleUnexpectedException(PublishingPage newPage, Exception exception)….

Also this error also wouldn’t even let the content deployment job to succeed.

pageinstanceerror

After scratching my head for a couple of hours I finally found the issue/resolution and thought to share the same with the community.

The issue circles around the Content Type Association feature which we leveraged to binds our custom content type instance with the MOSS Pages library.

Background:

The content types we created for sprint 1 inherited from MOSS Page content type and accordingly they we associated them with the designated page layouts, packaged and deployed on authoring environment.

Everything worked fine here!!

Later in Sprint 2, due to some change in the customer requirement we had to update our custom content types to inherit from a different content type – ABC content type (provided by the customer). So accordingly we updated the IDs for all the content type but rest of the properties (like Name) remained same. This update was again packaged and redeployed on authoring environment.

The above error occurred!! 

Root Cause:

Now once you redeployed a branding WSP, it would first delete the existing site content types and columns and other stuff but!! it won’t update the content type associations which are already there with the Pages library (at least for the content types having the same names). So our content types instances (apparently stale) in Pages library continued to inherit from Page content type instead of ABC content type. And here we ended up with two versions of content types with duplicate names.  

Solution:

Just delete the stale content type instance from the Pages library before you redeploy the new package and everything should work fine. Simple isn’t it J

Friday, July 23, 2010

Duplicate web parts shown in SharePoint publishing page layouts and page instances


Recently I came across another interesting issue with SharePoint page layouts. For a project requirement, we created some page layouts with almost the same structure having couple of predefined web part zones. Further each web part zone had a predefined Content Editor Web Part (CEWP). After packaging the same, I deployed the WSP on our test environment.

As pictures speak more than words, the screen grab below (left most) depicts the issue I encountered. When creating a page instance using any of our custom page layout, every web part zone showed duplicate CEWP web parts instead of just one CEWP.

Page instance in edit mode

  Page layout in SPD

Inspecting the page layouts in SharePoint Designer (SPD) resulted in the screen grab above (right most). The same duplicate web part appeared on the design mode.

At first I tried to repackage and redeploy the page layouts a couple of times thinking this would solve my issue, but was disappointed. Again, everything worked fine on the development environment where the page layouts were designed and created. It’s only when I packaged and deployed the page layouts via WSP and features this issue would show up.

I finally started inspecting the markup of the page layouts and found something interesting. I did a search for the web part zone GUIDs in SPD and below is the result of the query.

The result showed 82 occurrences of the same web part zone GUID in our custom page layouts (highlighted in yellow)!!.

 SPD GUID search result

 

 

 

 

 

 

 

 

Apparently what happened was the designer had taken the advantage of the fact that all the page layouts had almost the same structure and used the magic keys (CTRL+C & CTRL+V) to create them J

Issue:
Using the same web part zone GUID multiple times whether in same page layout or a different  page layout would result into the web part being shown up multiple times.

Resolution:
Ensure that every web part zone and web part in your page layouts have a unique GUID across your site collection.

Tuesday, January 12, 2010

SharePoint WCM Feature Generator

From my experiences on of SharePoint WCM projects I did so far, I came across certain repetitive & time-consuming development tasks. Some of them are listed below:

1. Creating Site Definition

2. Features

· Site Columns- Columns used in lists/libraries/page layouts.

· Content Types- Lists/Page Layout content types.

· Content Type Associations- Association of Content Types with the SharePoint list.

· Master Pages and Page Layouts- Provisioning master pages and layouts on SharePoint master pages library.

· Provision Files- Provision image, CSS, XAPS and documents on specified SharePoint library.

· Feature Staplers- Auto activation of features based on site creation.

3. Feature Receivers

4. Custom Controls

The image below illustrates the Visual Studio 2005/2008 solution for a typical SharePoint WCM project.

VSSolution

Keeping the same thought in mind, I have developed a utility SharePoint WCM Feature Generator to automate the feature creation for some of the fundamental WCM components in SharePoint like Site Columns, Content Types, Content Type Associations, Provisioning etc (indicated by green callout).

SharePoint WCM Feature Generator

Also this tool well integrate with Visual Studio to make things even simpler.

The SharePoint WCM Feature Generator is targeted for both Microsoft Office SharePoint Server 2007 and SharePoint 2010.

The tool can be downloaded from here: SharePoint WCM Feature Generator.exe

The user guide can be downloaded from here: SharePoint WCM Feature Generator User Guide

Saturday, June 20, 2009

How We Did It: SharePoint.Microsoft.com- So the recipe is out!!

Microsoft launched the SharePoint marketing Website on SharePoint Server 2007 last month. What’s interesting is the website interfaces a simple and an elegant look and feel, with Silverlight adding a jazz to the overall user experience.

SharePoint.Microsoft.com

From the manageability perceptive, the publishing infrastructure allows the content to be published and managed more quickly.

Our wonderful team Todd, Jomit, Meeta and Ritu and me - worked together to design and developed a whole bunch of components that fulfilled the overall requirements. Microsoft has also published the How We Did It article on MSDN highlighting the goals for rebuilding the website, the overall architecture and components used in the Website.

Friday, May 1, 2009

OOB publishing image field with hyperlink bug: Resolved

Couple of times SharePoint presents an odd behavior. I came across one of such behaviors recently where the publishing image field was getting rendered incorrectly when seen in the display mode. Instead of showing the image the publishing field shows the IMG tags.

Searching around the internet I found other people reporting the same issue followed by a workaround given by Stefan Gossner on his blog.

The workaround he suggested includes creating a custom field control which inherits from the RichImageField class.

After implementing the same I was able to get rid of this issue, but soon i discovered one more bug :-( . It was if you assign a hyperlink (e.g. http://www.microsoft.com) to an image, then the publishing image field also renders the hyperlink along with the image.

This occurs specifically in case when the hyperlinks include the protocol with them (http or https etc.).

After inspecting this issue I found that it was all due to the malformed anchor tag.

A well formed HTML output should be:

<span dir=""><a href="http://www.microsoft.com"><img alt="" border="0" src="/PublishingImages/ add.gif" style="BORDER: 0px solid; "></a></span>

But with the issue it was:

<span dir=""><a href="<a href="http://www.microsoft.com ">http://www.microsoft.com </a>" target="_blank"><img alt="" border="0" src="/PublishingImages/add.gif" style="BORDER: 0px solid; "></a></span>

To rectify this issue i took Steffan’s approach as the baseline and modified the code to look like this:

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.IO;
using System.Web;
using System.Web.UI;
using Microsoft.SharePoint.Publishing.WebControls;

namespace CustomPublishingField
{
public class RichImageFieldControl: RichImageField
{
protected override void RenderFieldForDisplay(HtmlTextWriter output)
{
if (this.ListItemFieldValue != null)
{
StringBuilder item = new StringBuilder();
item.Append("<span dir=''>");
item.Append(this.ListItemFieldValue.ToString());
item.Append("</span>");
output.Write(item.ToString());
}
}
}
}

So what I did here is pretty simple. I am taking the value of the ListItemFieldvalue property of the control and wrapping it under span tags. This generates the correct html and as a result the image gets properly rendered with hyperlinks.