Unknown's avatar

Posts by Simon Doy

I am an avid SharePoint enthusiast who works as an Independent SharePoint Consultant based in Leeds, United Kingdom. I am one of the organisers of the Yorkshire SharePoint User Group in the United Kingdom. I have been designing and building SharePoint solutions since 2006.

Why the out of the Box Content Query Web Part Item Style names friendly and custom styles aren’t


Introduction

 

So firstly this post comes about because I have been working with the Content Query Web Part quite a lot recently and this particular behaviour has been bugging me for ages.

However I have just got back from the European SharePoint Best Practices Conference where Christine Wheeler did some great sessions on the Content Query Web Part and I was hoping to ask her why the following behaviour happens.

However, just before I put my hand up she bet me to it and asked the audience if anyone knew why custom item styles don’t have friendly names and out of the box styles do.

So I thought I really should find out why.

 

Background

So what the heck am I talking about?

Well its this section of the Content Query Web Part that is the problem:-

image

This custom item style “CustomItemStyle” template has an unfriendly name compared to the other out of the box styles.

This screen is reached in the Content Query Web Part by the following:-

  • insert a content query web part on the page
  • Modify its properties
  • Expand the Presentation grouping and you will see two drop-down boxes
  • Group Style and Item Style

image

The “Out of the Box” item styles are displayed as readable descriptive list items.

What commonly happens is that new styles need to be created as none of the out of the box styles give the format that is required. It is possible to create your own style by :-

  • opening SharePoint Designer
  • create a copy of the XSLT style sheet ItemStyle.xslt found in Site Collection Root/Style Library/XSLT Style sheets
  • copy an existing item style template <xsl:template></xsl:template> image
  • give the <xsl:template name attribute a new name and change the match attribute to contain the same text as the name attribute.

Further information can be found in this great post (http://blogs.msdn.com/b/ecm/archive/2006/10/25/configuring-and-customizing-the-content-query-web-part.aspx) on the Microsoft ECM Blog.

When you have added a new style, then you will see the something like below.image

 

There does not seem to be away to control the description and give a friendly name. Looking through the components that make up the Content Query Web Part it would make sense that one of the following style sheets would help:-

  • Header.xslt
  • ItemStyle.xslt
  • ContentQueryMain.xslt

image

I would have expected ContentQueryMain.xslt to have some XSLT that would perform a look up which we could then add to allowing custom friendly ItemStyle descriptions.

 

Investigation

So I started thinking well how does the Content Query Web Part get this information?

The best way to find out is to reflect the code.

The Microsoft.SharePoint.Publishing.dll assembly is where the ContentByQueryWebPart lives so I fired up .NET Reflector and started to disassembly the Microsoft.SharePoint.Publishing.dll

The first place to look was at the class Microsoft.SharePoint.Publishing.WebControls.ContentByQueryToolPart the ToolPart is the control which displays the interface when you modify the web part settings on a SharePoint page.

The control has the following function, populateItemStylesDropDown() this calls back into the parent web part control using function PopulatedItemDropDown passing in the path ~SiteCollection/Style Library/XSL Style Sheets/ItemStyle.xslt.

image

image

The PopulateDropDown is then called with the XSLT Style Sheet link and also the “ItemStyle” string. It is this function where all the item styles are discovered and added to the drop-down list box.

image

If you look at the highlighted section the code tries to resolve a string within a resource file using the Item Style name attribute and prefixing the Item Style name with “ItemStyle”.

If a string is not returned then the template name found in the XSLT is used and hence this is why we see unfriendly style names with custom Content Query Item Styles.

So where are these Item Style names stored?

Well the function Resources.GetString() function is called and the Resources object is also found in the Microsoft.SharePoint.Publishing assembly as Type Microsoft.SharePoint.Publishing.Internal.Resources.

image

The class has a default constructor which defines the details of the resource file to open. It happens that the resources are actually held within the Assembly Microsoft.SharePoint.Publishing.Intl.dll which is found in c:\program files\microsoft office servers\14\bin directory.

image

The Microsoft.SharePoint.Publishing.Intl.dll has embedded resources, one of them being Microsoft.SharePoint.Publishing.Strings.resources, this contains all the Item Style resource strings.

image

image

 

So there you go, that is how the Content Query Web Part displays readable Item style descriptions!

The next question is how do we go about doing our own version of this?

That is something that I haven’t thought about yet. I would be interested in hearing from you on how you would approach this issue.

Unable to create a page based on a Publishing Page Layout


Introduction

This issue reared its head a few weeks ago. One of my clients has a pretty heavily customised Intranet which uses custom site definitions with feature stapling etc.

I have advised them to use separate site collections to help keep their site collections secure but with the main advantage being that they can use separate content databases for each site collection. This is to help ensure that they don’t get large 100Gb databases and issues with SQL Server locking.

Anyway, recently we started seeing an issue where the various contributors to the site (who were not site collection admins) could not create a page using the normal site settings->create page.

They had contribute rights but would get the error message:-

“The list does not exist”

 

Solution

So I started thinking about what the problem could be. The list does not exist message was being displayed before a page has been created and as soon as the user clicked Site Settings->Create a Page.

When you create a page you get a list of page layouts to choose from. So that brought me to checking that the master page gallery was there. I thought maybe someone had deleted the list or a feature had not been activated properly.

The list was there but no permissions were set, ah I thought that will be it.

I added the [Site Name] Members and [Site Name] Owners groups giving the Owners group Contributor permissions and the Members group Reader permissions.

The users could now create page successfully.

The reason that the problem was happening is that as part of the site collection creation process the content managers were being good and cleaning up the unused out of the box publishing SharePoint groups.

These groups include the following:-

  • Approvers
  • Designers
  • Hierarchy Managers
  • Quick Deploy Users
  • Restricted Readers
  • Style Resource Readers

However, this process was removing all the permissions from the master page gallery and hence any users who which were not site collection admins could not access the list.

The next step to this solution is write a Feature Receiver to clean up the SharePoint groups and clean up the permissions, this should help make things easier and ensure that users can start using the site as soon as its setup.

That will have to wait for a further blog post though.