Archive for January, 2008

Handling Errors when doing file IO

I came across a pattern in .NET that I’d not thought of before. The scenario is, I’m reading from a file and deserializing it’s contents (a List of ‘Foo’ objects). Exceptions can be thrown at two points:

  • When I’m reading the file
  • When I’m deserialising the xml

Obviously, I want to make sure that the file handle is released if the deserialisation fails. However, I can’t deal with that in a single try block, as if the exception is in the file IO, then the file handle won’t exist to close in a finally block! Read more »

Alien V Predator : Requiem

So, I was standing outside the cinema last night, and I noticed that there is a film out now of Aliens (as in ‘Alien’) fighting the predators (as in ‘Predator’). In fact, it’s the second film of these bizarrely mixed franchises.

Now, between that and the host of sequel films, formulaic comedies and remakes (St. Trinians!?, I am Legend), it seems that Hollywood has run out of new ideas. Maybe it’s the screenwriter’s strike thing. Anyway, I thought to myself ‘What would the natural follow up Aliens vs Predator 2′ be? Well, I’ve got it…

Aliens vs Predator vs Godzilla

Now, naturally Godzilla would struggle a bit with tiny invisible predators - I mean, Lego men are easy enough to loose, let alone invisible Lego men (I’m thinking relatively here), but I’m thinking that Godzilla could cause enough damage to inflict a fair bit of damage. And Godzilla’d be immune to the Alien face-hugger things - after all, he’s 300ft high, and breaths fire - kinda hard to get down that throat.

And then…

Aliens vs Predator vs Godzilla vs The A-Team

I haven’t yet figured this one out yet, but there must be some way of getting the A-Team trapped somewhere which happens to contain a lot of steel, an cutting torch, and every snap-on tool known to man. They can make themselves a powered exoskeleton to fight the Aliens (we know they don’t like that), while BA rips off his shirt to go man0-a-mano with one of the Predators. I pity the fool who touches his gold!

Screenwriters. Bah! Who needs ‘em?

.NET Framework versions, language versions, and CLR versions - all a bit fraught…

The .NET framework is a bit confusing until you get your head round the components of it, and the way that Microsoft name things.

.NET has a thing called the common language runtime (CLR). (This is the .NET equivalent of the Java Runtime). Different versions are essentially different VMs, and can coexist. The CLR runs code that is an Intermediate Language (IL) (aka the Common Intermediate Language (CIL)). Whatever code you write in C# or VB.NET actually only gets partially compiled into IL code. It’s a lot like Java Bytecode.

The Base Classes are the library of DLLs for the framework (and are sometimes incorrectly referred to as the framework). Think of it as Win32 for .NET. These constitute the .NET API – and have different versions too. A different version of the base classes, though, does not mean a different CLR – for example, frameworks version 2, 3 and 3.5 all use the same CLR, but present a different external API and have different language features. Indeed, the base classes of framework version 3.5 are a superset of version 3, which are a superset of 2. This means framework 2 code will run on machines with the 3.5 installed.

The languages have different versions too, and this is where things start to get confusing. The different language versions have different compilers, which emit backward compatible IL. This is to be expected since there is no new version of the CLR. In plain terms this means that all the new language features can be used with older projects. E.g. C# 3.0 code can run on the .NET 2 Framework, provided you haven’t used any of the libraries that are part of a later framework. The C# 3.0 code will be partially compiled into the same version of IL code as your C# 2.0 code, so the only problems come if you are using libraries that aren’t part of that .NET Framework.

 (Note to self - must remember - C# version is independent of  Framework version)

So why would you want to use C# 3.0 over C# 2.0? Well, the language adds a number of new features too – such as automatic properties, relaxed delegates, object initialisers, type inference, anonymous types, extension methods, lambdas and partial methods.

Hopefully this chart might explain things a bit. I’m pretty sure it’s right, although I’m recreating it from memory and can’t entirely remember…


Framework Version 1.1

Framework Version 2.0

Framework Version 3

Framework Version 3.5

CLR

1.1

2.0

2.0

2.0

Library versions

1.1

2.0

3.0 (including 2.0 sp1)

3.5 (including 2.0 sp1 & 3.0 sp1)

Similar chart here:

http://www.leonmeijer.nl/archive/2007/06/11/50.aspx

…though the Microsoft guy who presented to me didn’t say anything about a CLR 3.0. I suppose there may be one which is backwardly compatibile?

Changing the SmallSearchInputBox delegate control

A colleague of mine was wanting to make some changes to the SmallSearchInputBox delegate control in SharePoint 2007. That’s the control that appears on most pages, looking like:

SmallSearchInputBox

This control is a ‘Delegate control’ - that is, you can create features to override the currently used control. What my colleague wanted to do was not display the ‘Scope’ drop down list, the Advanced Search link, and to include prompt text (something like ‘Enter Search…’). A quick dig into the FEATURES folder in 12 Hive showed that the control had a number of properties.

(The features that this information applies to are the OSearchBasicFeature and OSearchEnhancedFeature. Both contain files called ‘SearchArea.xml’, and that contains the code below. I found the folders with this in:

%12 Hive%\Template\Features\OSearchBasicFeature

%12 Hive%\Template\Features\OSearchEnhancedFeature )

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Control
Id="SmallSearchInputBox"
Sequence="25"
ControlClass="Microsoft.SharePoint.Portal.WebControls.SearchBoxEx" ControlAssembly="Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">
<Property Name="GoImageUrl">/_layouts/images/gosearch.gif</Property>
<Property Name="GoImageUrlRTL">/_layouts/images/goRTL.gif</Property>
<Property Name="GoImageActiveUrl">/_layouts/images/gosearch.gif</Property>
<Property Name="GoImageActiveUrlRTL">/_layouts/images/goRTL.gif</Property>
<Property Name="UseSiteDefaults">true</Property>
<Property Name="FrameType">None</Property>
<Property Name="ShowAdvancedSearch">true</Property>
</Control>
</Elements>

This shows a property ShowAdvancedSearch which sounded pretty promising for turning off the Advanced Search link. We decided to see what other properties were available, and found a good article by Clint Cherry about the SmallSearchInputBox control, and the MSDN docs. The Property tags in the XML for the delegate control set the properties of the web control class - e.g. GoImageUrl matches the GoImageUrl property on the class. Much to our pleasure, we found the QueryPromptString displays text in the search control which vanishes when it receives focus, and the DropDownMode property allows us to turn off the scope dropdown list. Hurrah!

For the values that you can set the drop down mode to, see the MSDN docs again

What happens when a K2 BlackPearl Licence expires?

So, I’d built a demo with a short-term licence key - one that expired at the end of December. This was unfortunate as the demo got moved to January. Anyway, what happened when the licence expired? Um, sudden workflow death. The workflow host ceased functioning - so my workflows which were in progress wouldn’t do anything, and even the worklists stopped functioning.

Hmm. Seems a bit brutal to me - I’d expected that the in progress workflows might be possible to continue, albeit that I wouldn’t expect to be able to start new processes. I suppose maybe it makes sense, ‘cos otherwise people would be able to still be using ‘in progress’ workflows for years afterwards, but it was a bit of a shock.

On the other hand, updating the licence wasn’t too hard - provided you can find the URL

Why SharePoint Records Management will struggle…

I recently got a lot of my old APS photos scanned, and I’ve been working my way through them all, trying to sort them out and arrange them. I’ve been doing this by, well, putting them in folders such as ‘2003-06 - French Alps Kayaking’. At the same time, though, I wanted to give my friends copies of the photo’s which they were in, and I did this by, well, creating another folder for each of them, and copying pictures into them too. Not dreadfully sophisticated.

A couple of my friends asked why I didn’t just use some albuming application, or something like Flickr, and tag the images. That way, I could browse by multiple criteria. And I’ve gotta say, it would be neat. However, I want to be able to look at these photos when I’m an old man. I mean, my grandfather was showing me pictures of when he was a kid - so that’s about 75 years ago. Does anyone consider 75 year survival times for digital media? Nope. But I suspect that file systems and JPEGs, even if they aren’t still in use, will be easier to migrate. Flickr? Well, obviously, no website has ‘Established 1932′ on it. I’m not sure I’d trust something like that to still be around. Other tagging and abluming products - again, I’m not convinced. I decided I’d stick with just folders.

This set me thinking about Record Management, and taxonomy vs tagging. Read more »

Setting up an Email Server

A short, useful article about setting a machine up as a mail server - this proved useful when I was setting up a machine for a demo recently. I must confess, I’ve never set up a mail server before, but it was quite simple, apart from the problems I had with finding the right Windows Server installation disc.

“Error occurred adding the feature to the farm” when deploying K2 workflow

This problem proved a real puzzler for me - but the guys on the K2 underground came through with a good answer - the Application Pool Identity of the Moss Site Collection must be part of the Farm Administrators group. (Which makes sense when you think about it. The K2 web services are running under the App pool identity of the site collection, and they’re trying to deploy features to the farm…)

Unfortunately, I then suffered a second problem - and error of ‘Value cannot be null’ when trying to deploy a workflow associated with a SharePoint Content Type. Sadly, all this was worked on last minute just before Christmas, so I’ve forgotten a lot of what I did to my machine. I met with some of the guys from K2 who were very helpful, and we did quite a lot. My memories are:

  • Installed SP1 for [blackpearl]
  • Installed Office 2007 (I was in a hurry and forgot, okay?)
  • Stopped trying to associate the workflow with a content type and instead associated it with a specific list - which worked for the demo, but associating with the content type is a far, far cooler idea.
  • Changed my form to allow “Cross-Domain Access for User Form Templates” and changed the data connection timeouts in SharePoint to be longer - as several of the guys in the thread noted, this does seem to be an issue with K2 workflows in VMs - but then my 2GB RAM machine was running a VM with MOSS, SQL2005, K2 and a DC, SMTP and POP services on it.
  • Gave more rights to K2 to some of the users. I had to give the App pool more permissions than I had, in order to allow it to display worklists, which also makes sense.
  • Sorted out a misconfiguration in IIS.

I’m sure I’ve missed other things, but it was so long ago now, I can’t quite remember. The only other thing I can remember doing was sitting around a lot waiting for everthing to work. The applications were quick enough when they’d been compiled, but that meant that the first time I hit some of the pages, well, there was a lot of waiting. And errors from timeouts. Particularly we had problems with contacting SQL Reporting Services from some of the K2 wizards, but found that if you waited a moment or two and then tried again then they were okay.

Uploading Files to SharePoint using the Web Services

Thankfully, someone seems to have looked at other ways of uploading files via the web services - this time using a direct PUT command. That is an approach which is a little odd, to be honest, and I suppose not really Web Services so much as plain old web-server. Still, I’m going to have a look at this approach - and it’d be great if it works.