Archive

Archive for November, 2011

Site Navigation with a Content Query Web Part in a SharePoint Page Layout

November 1, 2011 Leave a comment

A brief on one of my current projects was to create left hand navigation for an new Intranet which was built up from the Pages library.  As is usual with Intranets, the content was spread across multiple publishing sites under a single Site Collection, hence each site had it’s own Pages library.  It’s a simple task to set this up for each page using the Content Query Web Part (CQWP) but ideally this should be part of a Page Layout that can be used on every site.  

The other requirement was that the Title of the Web Part should be that of the current site, so Information Technology if the user was view pages from that site, Operations for the Operations site etc.

Out of the box, this would not be possible as the CQWP is linked to a single library and it’s Title is set from the Web Part Properties. You obviously could add a CQWP to each page but this is inefficient and beyond most content editing users. So for a more elegant solution you’ll need to use Visual Studio to create your own Web Part, however the code is extremely straightforward and is derived from ContentByQueryWebPart. You will need to include a reference to Microsoft.SharePoint.Publishing.WebControls in your project which is in the Microsoft.SharePoint.Publishing namespace and the code below should be enough to get you up and running.

public class ContentNavigation : ContentByQueryWebPart
{
 protected override void CreateChildControls()
 {
   SPWeb web = SPContext.Current.Web;
   SPList list = web.GetList(web.Url + "/Pages");
   this.ListGuid = list.ID.ToString();
   this.ListName = list.Title;
   base.CreateChildControls();
 }

 protected override void OnPreRender(EventArgs e)
 {
   this.Title = SPContext.Current.Web.Title;
   base.OnPreRender(e);
 }
}

Once packaged and deployed, it’s then straightforward to create a Page Layout containing this web part.

SharePoint, JQuery and z:row when using Chrome

November 1, 2011 1 comment

I’ve recently been using JQuery with SharePoint web services quite extensively and initially had a few issues with Chrome not rendering when the same code works fine with IE.  With this post I’ll show you what you need to change for cross browser compatibility as there seems quite a bit of confusion around the web.

A lot of code examples use:


$(xData.responseXML).find("z\\:row").each(function(){

whilst this works in IE & Firefox, it won’t function in Chrome or Safari, but if you are using JQuery 1.5 or greater, change this line to the following and you’ll have a working solution in all browsers.


$(xData.responseXML).find("[nodeName='z:row']").each(function(){

Categories: JQuery, SharePoint
%d bloggers like this: