Welcome to my blog on all things SharePoint. I have a range of articles that will interest you if you've made it as far as visiting my blog. I was awarded as an SharePoint MVP by Microsoft in July 2010. I currently live in New York and am an Enterprise Architect at AvePoint Inc.. I co founded www.NothingButSharePoint.com with Mark Miller in 2010.

MVP AwardJeremy Thake Profile Photo

Whitepapers

NBSP

Check out my articles on NothingButSharePoint.com

Solution Development in SharePoint 2007

This series was inspired by the chatter amongst SharePoint blogs on the best ways to approach customisations in SharePoint using Solutions.

Part 1 - Part 2 - Part 3 - Part 4 - Part 5 - Part 6 - Part 7 - Part 8

Leveraging the SharePoint Platform

This series was inspired by a discussion had with Andrew Coates at a Perth SharePoint User Group meeting. This then turned into a 6 part series on Arno Nell's SharePointMagazine.net web site.

Initial post - Part 1 - Part 2 - Part 3 - Part 4 - Part 5 - Part 6

Webcasts

I have recorded various web casts that I present at User Groups or just on a specific topic by request:
How ASP.NET Developers can leverage SharePoint webcast
SPSource Webcast: Reverse engineer Lists to ListTemplates and much more
SharePoint Development with Unit Testing webcast
Perth SharePoint UG Web Cast on approaches to deploying artefacts (SPSource)
More...


Podcasts

I have been interviewed about Leveraging the SharePoint Platform by the SharePoint Pod Show: listen here .

RSS Feed Feed your read!

Archives

November 2012 (6)
October 2012 (8)
September 2012 (4)
August 2012 (7)
July 2012 (13)
June 2012 (4)
March 2012 (1)
February 2012 (1)
January 2012 (5)
September 2011 (2)
August 2011 (1)
July 2011 (3)
June 2011 (7)
May 2011 (3)
April 2011 (3)
March 2011 (3)
February 2011 (2)
January 2011 (1)
December 2010 (4)
September 2010 (4)
July 2010 (5)
June 2010 (4)
May 2010 (6)
April 2010 (7)
March 2010 (5)
February 2010 (7)
January 2010 (3)
December 2009 (1)
November 2009 (6)
October 2009 (9)
September 2009 (7)
August 2009 (6)
July 2009 (13)
June 2009 (4)
May 2009 (12)
April 2009 (4)
March 2009 (4)
February 2009 (13)
January 2009 (4)
December 2008 (4)
November 2008 (11)
October 2008 (16)
September 2008 (4)
August 2008 (5)
July 2008 (4)
June 2008 (8)
May 2008 (5)
April 2008 (9)
March 2008 (5)
February 2008 (6)
January 2008 (1)
November 2007 (11)
October 2007 (8)
September 2007 (24)
August 2007 (5)
July 2007 (2)
May 2007 (1)
April 2007 (1)
March 2007 (1)
February 2007 (3)
January 2007 (4)
November 2006 (7)
October 2006 (7)
September 2006 (18)
August 2006 (14)
June 2006 (3)
May 2006 (8)
April 2006 (4)
March 2006 (38)
February 2006 (30)
January 2006 (2)
December 2005 (3)
November 2005 (28)
May 2005 (1)
April 2005 (5)
March 2005 (1)
November 2004 (1)
August 2004 (11)
July 2004 (1)
Failed to render control: An error occurred during a call to extension function 'createMonthUrl'. See InnerException for a complete description of the error.

Links

Tag Cloud

Ajax, Apple, DotNetNuke, Enterprise Content Management, Error Resolution, Gadgets, General, Governance, Microsoft .Net Development, Mobile, SharePoint, Sharepoint Business Forms, Sharepoint Business Intelligence, Sharepoint Collaboration, SharePoint Development, Sharepoint Enterprise Content Management, Sharepoint Enterprise Search, Sharepoint Portal, US Migration, Web 2.0, Workflow

Solution Development in SharePoint 2007 Part 5   

Tags: SharePoint
Technorati Tags:

Part 1 - Part 2 - Part 3 - Part 4 - Part 5 - Part 6 - Part 7 - Part 8

So the next part in my series will basically show you how to deploy a Content By Query Web Part (CQWP) and also it's associated elements. The screenshot below shows the structure of my project file now. The Solution package can be downloaded here.

 

Deploying the Content By Query Web Part

As I mentioned in my previous article, there are various ways of deploying the web part but I feel you have more control by using the API in the code behind rather than using the <Module> element method, there's plenty of links I've collected over on my diigo page. As discussed in my previous web cast, it is important to use the CommonViewFields property to set the Fields that are available in the XSLT.

public override void FeatureActivated(SPFeatureReceiverProperties properties) {

using (SPSite site = new SPSite("http://jt-asuslaptop/"))

{

using (SPWeb web = properties.Feature.Parent as SPWeb)

{

SPFile file = web.GetFile(web.Url + "/default.aspx");

SPLimitedWebPartManager webpartsMng = file.GetLimitedWebPartManager(PersonalizationScope.User);

ContentByQueryWebPart contentByQueryWebPart = new ContentByQueryWebPart();

contentByQueryWebPart.Title = "Schedule";

contentByQueryWebPart.WebUrl = web.Url;

 

SPListTemplateCollection listTemplates = web.Site.RootWeb.ListTemplates;

SPListTemplate template = listTemplates["Schedule"];

contentByQueryWebPart.BaseType = string.Empty;

contentByQueryWebPart.ServerTemplate = Convert.ToString((int)template.Type, CultureInfo.InvariantCulture);

contentByQueryWebPart.CommonViewFields = "Air_x0020_Date,AirDate;Episode_x0020_Number,Episode;Season_x0020_Number,Season";

contentByQueryWebPart.ItemStyle = "ScheduleStyle";

contentByQueryWebPart.ItemXslLink = site.Url + "/Style%20Library/jeremythake/schedule.xsl";

webpartsMng.AddWebPart(contentByQueryWebPart, "Right", 0);

}

}

}

 

Cleaning up

Cleaning up after yourself will keep your mum from lecturing you on the finer art of bed making! So with that in mind you should delete the web parts that you've installed on deactivating the feature. All the other stuff is automatically cleaned up such as style sheets etc.

 

public override void FeatureDeactivating(SPFeatureReceiverProperties properties) {

using (SPWeb web = properties.Feature.Parent as SPWeb)

{

SPFile file = web.GetFile(web.Url + "/default.aspx");

SPLimitedWebPartManager webpartsMng = file.GetLimitedWebPartManager(PersonalizationScope.Shared);

for (int i=0; i< webpartsMng.WebParts.Count; i++)

webpartsMng.DeleteWebPart(webpartsMng.WebParts[i]);

}

}

 

Writing the style sheet

The style sheet is where all the rendering magic happens. I use the ListAll xsl:template (configured in the ItemStyle property of the ContentByQueryWebPart) to render all the Fields to ensure that I've got the correct property names such as @Episode_x005F_x0020_Number which is not how it was added in CommonViewFields property e.g. Episode_x0020_Number,Episode.

 

Again, I noticed some formatting issues in the Number and DateTime and found some functions which I've diigo'd.

 

<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet

version="1.0"

exclude-result-prefixes="x d xsl msxsl cmswrt"

xmlns:x="http://www.w3.org/2001/XMLSchema"

xmlns:d="http://schemas.microsoft.com/sharepoint/dsp"

xmlns:cmswrt="http://schemas.microsoft.com/WebParts/v3/Publishing/runtime"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">

 

    <xsl:template name="ListAll" match="Row[@Style='ListAll']" mode="itemstyle">

        <xsl:for-each select="@*">

            P:<xsl:value-of select="name()" />

        </xsl:for-each>

    </xsl:template>

 

    <xsl:template name="ScheduleStyle" match="Row[@Style='ScheduleStyle']" mode="itemstyle">

        <h5>

            <xsl:value-of select="@Title" />

        </h5>

        Season: <xsl:value-of select="format-number(@Season_x005F_x0020_Number,'##')" />

        - Episode: <xsl:value-of select="format-number(@Episode_x005F_x0020_Number,'##')" />

        - Air Date: <xsl:value-of disable-output-escaping="no" select="ddwrt:FormatDate(string(@Air_x005F_x0020_Date), 3081, 1)" />

    </xsl:template>

 

</xsl:stylesheet>

 

Deploying the style sheet file

Linking to a custom style sheet actually is best practice due to not modifying the ItemStyle.xsl file as this is part of the base install of SharePoint and there is a risk of patches or new versions overriding this. The below code in the Feature Manifest file (elements.xml) allows the deployment of files pointed to in the Path folder attribute to a defined url by the URL attribute. I placed this in the Site Collection scoped feature.

 

    <Module Name="JeremyThakeStyles" RootWebOnly="TRUE" Path="Styles" Url="Style Library/jeremythake">

        <File Url="schedule.xsl" IgnoreIfAlreadyExists="TRUE" Type="GhostableInLibrary" />

    </Module>

 

The other neat thing about STSDEV is that you don't have to create .ddf files manually and so adding the .css file into the Visual Studio Project automatically includes it in the Solution .wsp package. You then only have to add an entry into the Feature file itself.

 

<ElementManifests>

        ...

        <ElementFile Location="Styles\schedule.xsl"/>

    </ElementManifests>

 

"There's one small problem!"

Although this all seems great, the line where I set the ItemXslLink throws an error when it's set...

 

Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Windows SharePoint Services-compatible HTML editor such as Microsoft Office SharePoint Designer. If the problem persists, contact your Web server administrator.

 

I've searched for solutions to this and can't seem to find the answer. The XSL path definitely is correct and I can get to "Modify My Web Part" without error. If anyone has any suggestions I'd greatly appreciate it.

"The others"

On my blogging travels I've found some great articles from other awesome SharePoint Experts.

Michael Blumenthal's post on "what do I give to my SharePoint Admin" poses a great question that often comes up from organisations of a size where they have someone who owns the Farm and won't let anyone else near it like a true guard dog! Every farm should be dealt with in this nature and a UAT environment should be in place to ensure that deployments work correctly before doing this in Production. The methods Michael uses are heading more towards Continuous Integration and having a Build server to automatically deploy the packages from source control built projects.

Isahi Sagi also wrote a good article on "planning a SharePoint solution" and point 8 again mentions issues around the fact that not everything can go in the .WSP package, for example InfoPath forms are deployed using stsadm commands. Following on from this, rather than having to type all the stsadm commands in it's better to provide the SharePoint Admin with a script to run to deploy the .wsp package. I'll discuss this in more detail in another post.

Chris O'Briens article has some great samples of Solution Packages. He's doing some great work with SPConfigStore on CodePlex also so check it out. There are lots of approaches to managing configuration per environment. Again, something else I'll be discussing...

Serge van den Oever shined some good light on the Solution Generator for exporting Site definitions and points out some interesting facts about what is exported.

There is also some good presentations from DevConnections too which give a good overview of Solutions.

Waldek Mastykarz also has been busy blogging around this space and seems to be a very good contributor to the MSDN Forums around this too. Waldek makes some great points about big WCM projects where you just simply wouldn't want to script the whole thing as a Feature because it would simply take too long, definitely worth a read on his thoughts on Deployment.

Obviously every man and his dog has blogged about VSeWSS 1.3 so if you hadn't heard about it...you know now ;-)

 
Posted by  Jeremy Thake  on  6/7/2008
5  Comments  |  Trackback Url  | 1  Links to this post | Bookmark this post with:        
 

Links to this post

Comments


  commented on  Wednesday, August 06, 2008  5:29 AM 


Apperfeld  commented on  Tuesday, September 23, 2008  6:51 AM 


Donovan Regel  commented on  Wednesday, December 17, 2008  12:50 AM 
Hi Jeremy. In terms of clean-up, what if there is more than one feature that activates webparts on the page. Your clean-up code seems to delete them all. Can you delete only the webparts inserted by the feature in question, or can you delete them by name or some other identifier?


Remco van Beek  commented on  Tuesday, March 17, 2009  2:08 PM 
Hi Jeremy. You have searched the internet for puting in the right path to the XSL file. What i have discovered is that things go wrong when you use a relative path "sites" for hosting your site collection. The solution is used is to create a new webpart that inherits the CQWP. In the base class put the following. public class MyCQWP : ContentByQueryWebPart
{
public MyCQWP()
: base("/Style Library/XSL Style Sheets/ContentQueryMain.xsl",
"/Style Library/XSL Style Sheets/Header.xsl",
"/Style Library/XSL Style Sheets/CustomItemStyle.xsl")
{

}

}


Bilal  commented on  Friday, July 24, 2009  10:40 AM 
Is this gonna work if I use Feature Stapling for this feaature ?

Actually I know it won't because features are activated much before default.aspx page is provisioned..

so reference to default.aspx page will return null.

Can you suggest any idea how to do it ?

Bilal

blog comments powered by Disqus