Archive for March, 2008

Filtering ListView Web Parts and Spurious Error Messages

I was working with a customer on building a glossary in SharePoint. We had a list of terms, containing things link ‘Term’, ‘Description’ and ‘First Letter’. They wanted, on a page for the site, to show the terms, and allow filtering based on the first letter.

I set up a page with a ListView web part and a filter web part. The filter web part would supply the letter we wanted to filter by to the ListView, which would then filter on the first letter column. As a side note, I started by using the Choice Filter web part, which isn’t just a drop-down list but is rather uglier - so in the end I just used a QueryString Filter web part and built my own navigation for the filter. This was why I ended up looking at how to show query string parameters within a page.

Anyway, this worked nicely - except that the ‘First Letter’ column on a web part is a little redundant if you are filtering by that letter already. Thus, we tried removing that column from the list view web part, and got the spurious message:

This page has exceeded its data fetch limit for connected Web Parts. Try disconnecting one or more Web Parts to correct the problem

Initially I thought that this was because we had 700 items in the actual glossary I was now building against (previously I’d just prototyped it with a half dozen items) - but to not be able to filter over that is pretty rubbish. However, when I put the ‘First Letter’ column back into the ListView, the error went away. So, if you get this error, make sure the thing you are filtering by is visible as a column in the ListView.

Good quick guide on “Showing list items from another site”

As usual, a good article from U2U on “Showing list items from another site“. This is very useful with the DataView web part, though as noted at the bottom there are some limitations - particularly the lack of views, and editing. It’s worth reading the article, but in short (for my own memory), in SharePoint Designer:

  1. Manage data sources
  2. Connect to another Library (by which they really mean ‘Site’ - use the site url, not the library url)
  3. Drag data in as DataView web part
  4. Use smart tags to set up columns, filters, grouping, pagination, etc..

KPI Icons neatly designed for colour blindness

I was talking with one of our customers about SharePoint branding the other day. They’ve got some neat icons for displaying the status of things. However, the guy I was talking to wasn’t keen on them as they were the same colour (although their shape differs). This sort of led around to a discussion of the use of colour (or ‘color’) in web development.

One of my ‘neat tools to have around’ is the Color Contrast Analyzer (which I think you can get here -I must confess, I’m not sure who exactly wrote it or where exactly you’re supposed to get it from). This little tool lets you check the contrast of colour schemes so that your users will be able to use the site, even if they’re colour blind. Fair enough. The really exciting bit, though, is the ability to take screenshots and then simulate the different types of colour blindness.

I used this to look at the SharePoint KPI icons. Similar icons to this are available in Excel 2007 for conditional formatting. I thought this was pretty interesting. For a start, it turns out that colour blindness is more complicated that just “red-green-blue” colour blindness, not least because the photoreceptors for the different colours overlap in their response to different frequencies of light. Still, this tool give a good view of the effects of the main conditions. For a full description, read this article at Wikipedia.

KPI - Normal
Normal
KPI - Greyscale
GreyScale
KPI - Deuteranopia (Red-Green Colour Blindness)
Deuteranopia (Red-Green Colour Blindness)
KPI - Protanopia (Different Form of Red-Green Colour Blindness)
Protanopia (Different Form of Red-Green Colour Blindness)
KPI - Tritanopia (Blue-Yellow Colour Blindness)
Tritanopia (Blue-Yellow Colour Blindness)

What this shows is pretty obvious - that the icons from red and green are pretty similar for red-green types of colour blindness (what a surprise), but that the shape of the icons still gives a good visual cue to the state of the KPI. Given that (according to Wikipedia) 7-10% of men are Red-green colour blind, this is important. It’s worth noting that women are very rarely colour blind, and that this probably explains my Dad’s dress sense and my Mum’s opinions on it…

Error “This item cannot be deleted because it is still referenced by other pages”

I was trying to delete a master page in SharePoint designer, and I got the error “This item cannot be deleted because it is still referenced by other pages”. This was strange, as we knew that the master page had been reset for all sites in the site collection. We simply couldn’t find a reference.

Well, it turns out that this is a bug, and that Katrien De Graeve has an answer - create a folder, move the master page into the folder, delete the folder. Bizarre, but it works. And I have no idea how the heck they figured that out…

Showing Query String parameters in a page in SharePoint

I came across an interesting little problem with putting query string parameters for an HTTP request into a SharePoint page.

I was using a Dataview web part, which accepts query string parameters into the filter that it runs over the data that it’s going to display. That’s pretty cool - I had a list of items with a status column, and I wanted to be able to filter the items based on that status, and that the status would come from the query string. However, on the page, I also wanted to show a title with what was being filtered by in it. So, for example, my url might read:

http://server/site/page.aspx?status=Ready

And I wanted the title in the page to read “Filtering by ‘Ready‘”.

What I didn’t appear to be able to do was to just use the request object . Something like

<%= Request.QueryString.ToString() %>

won’t work as code blocks aren’t, apparently, allowed in the file - the error message is “code blocks are not allowed in this file”. Okay, given that SharePoint designer is supposed to open these pages up to ‘Power Users’ I do get why code blocks aren’t allowed. But I really wanted to write code, and there had to be a way to do that. Well, Kirk Allen Evans has figured out how - you have to enable them in the PageParserPaths section of the web.config file. (It’s strange how easy it is to forget the web.config file that controls SharePoint sometimes). Just to repeat his example (in case blue and red on black is difficult to read):

<PageParserPaths>
<PageParserPath VirtualPath="/pages/*" CompilationMode="Always" AllowServerSideScripting="true" />
</PageParserPaths>

This example allows code blocks for all files under the /pages directory of my web application - it’s worth noting that this is for the web application in IIS, not a SharePoint site collection or the like.

Okay, so that works - great. However, there are security implications, and this is probably best only used for development environments. I’ve written a bit about under what conditions our inline code will run.

In our instance our customer is kind of reluctant to make changes on their server. Changing the web.config file would be a bit of a bit deal. (As a side note, this is a bit restrictive - I think a blog posting on that is due sometime). So what could we do without a server footprint?

Well, without code in the page, we would need a web control to call in that page - that would work also. It’d be trivial to write one. However, that requires deployment, marking as safe in the web.config file, etc., so really that just pushes the problem into another file.

Thus, I ended up getting a bit ‘old skool’ - JavaScript in the page to write the value from the query string on the client. I came up with:

<script type="text/javascript">
var query = window.location;
var regex = /letter=([^&=]+)/i;
var match = regex.exec( query );
if( match != null ) {
document.write( “Filtering by ‘” + match[1] + “‘” );
}
</script>

What this code does is it gets the page’s url (window.location), runs a regular expression looking for the ‘letter’ parameter, and if it find one, it outputs some text to the document. A bit noddy, but simple and it works - with no server footprint. Of course, you do need JavaScript enabled…

« Previous Page