Tuesday, 26 May 2009

Annoying content source bug

I recently came across this annoying bug when setting up content sources recently.

If you try and specify multiple start addresses which differ only by query string then you get an error.



The error is "the object you are trying to create already exists. try again using a different name"



It seems that SharePoint uses only the main part of the URL for adding these to an internal collection. Using Reflector on Microsoft.SharePoint.Portal.Search.Admin.Pages and following the code path through confirmed this to be the case.

The solution is to create a page with those URLs on and crawl that instead. Not the end of the world but annoying all the same.

Wednesday, 11 February 2009

MOSS publishing sites and download aspx file problem

A project I was working on recently experienced a peculiar problem where users would browse to a page and be prompted to download the page e.g. save home.aspx somewhere locally. This was a MOSS publishing internet public facing site with multiple web front ends and page output caching set up.



The downloaded page was not the aspx source itself but the properly rendered HTML.

The problem was seemingly random and intermittent, it would appear on different web front ends and an IISRESET would cure the problem for a while but then other pages would then start to suffer from the same problem.

Eventually after finding a page which exhibited this behaviour and using Fiddler to look at the headers of the request and response I saw that the response content-tye header was set to "text/vnd.wap.wml" and not "text/html" as one might expect.

The problem was that the first person to hit that particular page was using a mobile browser whose user-agent string and Accepts header were making SharePoint/IIS return a content type like that above. Unfortunately this response was then place in the page output cache in MOSS.

When the next person to come along requested the page using a full fat browser like IE or Firefox, those browsers did not know how to handle the content type and offered to save the file instead!

Solution?

To vary the output caching dependant on the browser in use. Care is needed here to not impact the efficiency of the caching too much. You could for instance use the site output cache profile settings and choose user-agent against the vary by HTTP header. This is less than ideal however as user-agent strings can vary greatly:-

"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506)"

Different browsers, versions of browsers, .NET versions installed in the case of Windows PCs and multiple combinations of each can lead to dozens of potential user-agent strings. Storing a separate version of each page for each one would be very wasteful.




A better solution would be to just store a different cached version per browser i.e. just part of the user-agent string. This can be achieved by implementing a vary by custom handler on your site.This implements the IVaryByCustomHandler interface and your own logic determines what to base the output cache on.



There is an MSDN article detailing this here:-

http://msdn.microsoft.com/en-us/library/ms550239.aspx

and my implementation:-


public string GetVaryByCustomString(HttpApplication app, HttpContext context, string custom)
{
//The code looks for parameters specified in the cache
//profile that are passed to the handler and parses those
//delimited by a semicolon.
StringBuilder sb = new StringBuilder();
string[] strings = custom.Split(';');
bool appended = false;
foreach (string str in strings)
{
switch (str)
{
case "PWBrowserCheck":
if (appended)
sb.Append(';');

sb.Append(Request.Browser.Type.ToString());
break;


default:
continue;
}
appended = true;
}
return sb.ToString();
}

Thursday, 3 July 2008

SharePoint site columns and a mngfield.aspx error

I came across an interesting SharePoint bug recently when deploying custom site columns to a site collection.

Some people were complaining that they couldn't get my colour calendar solution to work properly on their systems. That when they installed they got an error trying to view the site column gallery. It turns out that there is a bug in SharePoint to do with the site column gallery and URL case sensitivity.

In the MSDN forums someone had come across the problem before (search for post by CorbyH425) http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=2863822&SiteID=1

My solution contained some custom field definitions in an elements XML file. I was trying to install to a site collection but not the root one.

Let's assume the site collection was created on this URL :-

http://mybigsite.com/sites/MWBigSite1

I then install my solution, deploy my solution and activate the site collection scoped feature passing the following url to stsadm :-

http://mybigsite.com/sites/mwbigsite1

If you then navigate to the site column gallery in the root of the site collection http://mybigsite.com/sites/mwbigsite1/_layouts/mngfield.aspx an error occurs.



A quick check with verbose logging switched on reveals the following

Application error when access /_layouts/mngfield.aspx, Error=Object reference not set to an instance of an object.

If you install, deploy and activate but provide the url the site was created on with the correct case then all is fine.

So although urls you use when deploying should be case insensitive it may pay to just copy and paste the actual url from the browser for stsadm purposes, alternatively, use stsadm to add the solution and the use the solution management UI in central admin to deploy and activate.

Tuesday, 15 April 2008

New release of colour (color) calendar v2.3

A new release of the colour calendar. Here are the changes:-

  • Field naming changes in the UI to make them more user friendly.
  • Event Category Title field does not appear when viewing details of an event.
  • Enable width fix option on colour coding web part - this implements the fix required to allow you to resize the calendar view web part without having scroll bars appear. (thanks to Kyle for this)
  • An instruction manual is now included in the release!

Thanks to everyone for all the feedback. As usual the release can be found here

Monday, 24 March 2008

Another MacBook Pro convert...

There seems to be a spate of posts like this extolling the virtues of MacBook Pros and here is another!

I needed a new laptop as I recently switched jobs and need my own kit now. After first trying a Dell M1530 (horrible screen) and then a Zepto (Scandinavia's largest laptop manufacturer! why oh why did I not go for a big name? anyway space bar didn't work) I decided I just needed something that worked and I was reading such great things about the MacBook Pros.

I went along to the Apple store and tried one out, I was hooked. These things are wonderful pieces of kit. Amazing build quality, fantastic screens, really slim and light. I went for a 15.4” machine as the 17” is just a little too big for my liking plus I have worked at 1920x1200 for a couple of years on a Dell but for the past few months was finding myself winding the resolution down as it was too high so the 1440x900 on the 15.4” is quite nice.

I got one of the new Penryn (new Intel 45nm processors) based ones and bought my own RAM for it. Chose the 2.4GHz as 0.1GHZ with a bit of extra cache simply isn't worth £300 extra.

Unlike most of the other SharePoint guys who have gone down this route though I have not decided to just run with Vista and here is why...

I want to use all of my 4Gb RAM which means Vista x64 or OSX (which has been 64 bit for a while) Now Bootcamp works really well and I have installed and used Vista on it fine. In fact the new OS X install DVDs which have the Bootcamp drivers on even have proper 64 bit drivers for all the devices in a MBP, smoothest install ever. However it is still Vista. I just can't stand it. It is harder to use than XP and is such a resource hog.

The biggest bottleneck in a laptop with VM work is typically the hard drive and Vista hammers it. The fact is that running VMs using VMWare Fusion in OS X is hands down faster and smoother than VMWare Workstation in Vista. I can run VMs with more memory or just more VMs with OS X. It certainly seems to handle memory pressure better than Vista. Also suspending and restoring VMs is soooo much quicker in Fusion it is unbelievable. I have no idea why and I tried fiddling with the settings in VMWare workstation but it made no difference. I know VMWare workstation is more powerful with more options but honestly Fusion does everything I need.

Not everything is perfect, the keyboard takes some getting used to and there are different shortcuts inside and outside the VMs. Also 2 USB ports isn't enough although fairly easily rectified with a small USB hub I carry with me. I haven't had the chance to try out a super fast Firewire 800 external drive yet. OS X has its quirks, the way windows maximise and minimise drives me a bit mad for instance.

I have a Bootcamped XP installation running in Fusion for running Office and any Windows apps I haven't found equivalents for in OS X (i.e. games and Outlook), this is all seamless due to Unity mode in Fusion (check out VMWare Fusion Unity on YouTube) Development VMs then sit full screen on their own desktops and it is a quick key press to jump from one to another.

About a month ago I spent 6 hours trying to sort out a friend's laptop that had been reduced to a never ending BSOD reboot loop due to Vista SP1 (not beta) being applied and decided life is too short to waste on it.
As most SharePoint dev takes place in VMs I just don't care about the host OS any more, OS X just works. There are so many little things about this new laptop which are cool, it has been a long time since I used a piece of technology and doing so made me smile....

Monday, 18 February 2008

Version 2 of the Colour (color) Calendar Released

I have finished working on what I hope is the final version of the colour calendar.

The previous version was well received but was lacking in a couple of areas. Firstly it required the creation of custom calendar lists. The custom list was based on the in-built calendar list but was missing some of the functionality like Connect to Outlook. Secondly you had to manually add the colour coder web part to calendar view screens.

The new version is built right into the existing SharePoint calendar list. Once you have deployed the solution you will find a new option under list settings for calendar lists to enable and disable the colour coding functionality.

Enabling the functionality creates the needed columns and adds the web part to any calendar views present on the list. Simply by clicking the enable button you will have a working colour calendar.

Disabling the functionality simply switches the display titles back to the default, it does not remove the colour coding web part or remove the columns so that you do not lose data. You can simply switch it back on again to see the colouring.



The colour coder web part works as before defaulting to a central colour mapping list in the root web but you can override to a local one if you wish.

If you add additional calendar views to your list, simply disable and then re-enable the functionality to have it applied to the new views.



It has been built so as to be upgradeable from the previous version. If you run the upgrade script as opposed to the deploy script then you will find your old colour calendar lists still work but the option to create a "Colour Calendar List" will be removed. You can obviously just use the new method for any new colour calendars you wish to create.

Thanks for all the feedback so far.

As usual the latest release can be found here

Regards,

Mark Wilson

Tuesday, 11 December 2007

ItemCount and Items.Count

Noticed a strange thing the other day, a list has the property ItemCount and also an Items collection which has its own .Count but they don't always give the same answer. If I have a piece of code like this pointing to a list with 4 items in it.

1 using (SPSite site = new SPSite("http://mwmoss/marktest"))
2 {
3 using (SPWeb web = site.OpenWeb())
4 {
5 SPList list = web.Lists["Mark's Contacts"];
6
7 while(list.Items.Count > 0)
8 {
9 list.Items[0].Delete();
10 Console.WriteLine("ItemCount " + list.ItemCount.ToString());
11 Console.WriteLine("Items.Count " + list.Items.Count.ToString());
12 }
13 }
14 }


The output looks like this:-

ItemCount 4
Items.Count 3
ItemCount 4
Items.Count 2
ItemCount 4
Items.Count 1
ItemCount 4
Items.Count 0

I guess internally some collection isn't getting updated as we go round the loop. Something to be careful of anyway.