K2 – Accessing environment fields from code

Posted in ASP / ASP.Net, K2 [blackpearl], Snippets on March 20, 2008 by Si

So I needed to get at the K2 blackpearl environment settings from the aspx pages I have been putting together. A quick trawl on the K2 user group (www.k2underground.com) quickly led to some code that lets you do just that (code below is based on that). You need to know the host server name and port number, but I put that in my web.config file to allow for configuration later when we move to the staging and live servers.

Using SourceCode.Workflow.Management;

WorkflowManagementServer server = new WorkflowManagementServer("blackpearl", 5555);

server.Open();

SourceCode.Workflow.Management.StringTable st = server.GetStringTable("Development");

SourceCode.Workflow.Management.StringTableEntry ste = st["field name"].Value;

server.Connection.Close();

Easy! Just remember to add a reference to the right assembly, SourceCode.Workflow.Management.

Joining the ASP.Net party – better late than never

Posted in ASP / ASP.Net, K2 [blackpearl] with tags , , on March 13, 2008 by Si

Yes folks, forever at the cutting edge of technology I have this week taken my first dive into the exciting world of ASP.Net 2, naturally on a key business project with short timescales – that’s the way we like ‘em!!

We have been developing some K2 [blackpearl] workflows, and had prepared beautiful InfoPath forms for handling user input and the like. However, trying to deploy the workflows to just six pilot SharePoint sites brought me that close from throwing my laptop out the window and storming off in frustration. K2 is simply not designed for that kind of deployment, but we had to get the pilot rolling and so that’s what we did. New deployments of smart objects and workflows customised for each site – torture!

So…… I am still in the job, and I have an undamaged laptop. We have decided to abandon the InfoPath forms as they were just too limiting, and abandon the pesky smart objects as well, and instead head over to ASP.Net 2 forms, with an even smarter interface! Yay! By doing this, we are able to code behind each page in order to do the stuff we couldn’t easily do before, like identify which site we are coming from, get into the SharePoint object model, and ultimately deploy just one version of our workflows that will apply to all sites.

My starting point for this adventure was the K2 Forms Generation wizard, which was very kind enough to generate a basic page which tied into the workflow server backend, so I had the hard work done for me. All that remained was a bit of css to get the right layout, and perhaps the use of a master page or two (as is good practice). And indeed, here I am, almost at the end of my first week, and I have the first page done! Ok it was a simple “type text in box, select value, click submit” page so not particularly taxing, but an achievement none the less I feel. I also have a tidy structured rough slap-dash class library containing a lot of functions I will use in the rest of the pages, and a crumb trail-type thing generated from an xml file. I’ll be the first to admit that it isn’t necessarily the smartest (in terms of code) solution, but it works, and that for me, at the moment, is the main thing.

Short timescales – well, it’s all got to be done by the end of this month (March), so no pressure! tick, tock, tick, tock……..

Si

Loader Lock error using DirectX AudioVideoPlayback

Posted in .NET, DirectX with tags , , , on March 9, 2008 by Si

I am knocking up a small app and need it to play a few sounds here and there. Now, most of them are straight forward wav files, which is not too much of a problem. However, I also have a few clips in mp3 format, and so have ended up using DirectX as a (supposedly) quick way out – DirectX.AudioVideoPlayback gives you access to a whole host of media functionality. So, having found a few examples on the web I dropped some code in and was then presented with the error message:

LoaderLock was detected

Message: DLL '.......\Microsoft.DirectX.dll' is attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.

Scary!! LoaderLock is one of the Managed Debug Assistants (MDAs) that Microsoft introduced in VS2005 to help track down and debug runtime issues in managed code. Anyway, here’s how to get round this issue:

  1. In VS2005, go to Debug > Exceptions (Ctrl + Alt + E)
  2. In the Managed Debugging Assistants section, scroll down till you find the offender (LoaderLock)
  3. Untick the box in the “Thrown” column. This is a per-solution setting, not a global setting!

Hey presto! Error message has gone. OK, I can hear you wondering, what about my app out in the real world – will it crash and bring the world to a standstill? Well apparently this MDA only affects code run under the debugger, so won’t be a problem. Incidentally, I tried turning the LoaderLock back on and mysteriously my app decided it no longer wanted to throw the error. Strange. So you may get away with turning it off, running your app then turning it back on if you are really concerned.

Si

Copying documents between SharePoint libraries keeping version history (part 2)

Posted in SharePoint with tags , , , , on February 22, 2008 by Si

Quick update on my exploits so far in trying to keep document version history when copying documents between SharePoint libraries (i.e. what I wrote in the title!!)

Good progress has been made from the starting point I mentioned in part 1. I have had to make a few changes to deal with the fact my libraries have major and minor versioning, which started me exploring the properties and methods available in SharePoint’s object model. To explore this further, I knocked up a noddy application which would allow me to experiment without going through the faff of having to deploy and trawl through my K2 workflow all the time, and in that I found some useful stuff for handling versions:

SPFile.Level is an enumerated property which indicates whether a version is draft, published or just checked out.
SPFile.CheckOutStatus indicates the nature of the checkout (long or short term), and so can also be used to determine if a file is checked out.
SPFile.UIVersion gives the 32-bit integer version number, whereas SPFile.UIVersionLabel returns the ‘user-friendly’ version number (e.g. 1.0, 1.1 etc…). Properties are also available that return just the major or minor part of the label, if that’s all you need to work with. (Note: when working with SPFile.Versions, use SPFile.Versions.ID and SPFile.Versions.VersionLabel respectively.)

So at this point it is easy to handle the different versions as necessary. The next hurdle is, well, an odd shaped one and I will hopefully find a reason and solution for it in due course. For some reason, I am having issues with handling the new Office 2007 format files. For example, versions of an old .doc (Office 2003) format file is fine, but a new .docx (2007) format file throws an error. I haven’t got the exact message to hand, but will grab it and post it later in case someone can tell me where I am going wrong! So for the moment, I have ignored this one, as most people who use this system are using Office 2003 so it will not be a great issue.

And so I will wrap up this post with a quick mention of checking in and out documents as part of the process. In dink’s example in part 1, the versions just get published, but as I said I need to handle minor and major versions. There is a minor check you need to do to see if the document is new in the destination library (my code copies new versions over existing documents as well!), and if it is, then you don’t need to check out first, you can just save. I should also point out that my libraries both have minor and major versioning, and require check in/out. Checking out is quite simple, just use SPFile.CheckOut(), and checking in is equally simple with the SPFile.CheckIn(String, SPCheckInType). SPCheckInType allows you to specify whether it is a minor or a major version.

This post is quite long enough already, so in part 3 I shall pop up some code (I can’t put it all up as it is technically proprietary, but then again this stuff isn’t rocket science!).

Si

Copying documents between SharePoint libraries keeping version history (part 1)

Posted in SharePoint with tags , , , , on February 20, 2008 by Si

Currently working on a SharePoint project which has a requirement to copy and move documents from one library to another. No problem, I said. Keep the version history as well, they said. Fine, I said. And then I set about it, thinking everything would just happen automatically when you move documents.

Except it doesn’t. Moving, or copying documents from one library to another seems to cause SharePoint to lose any version history, so the document gets checked in at version 0.1 (or version 1.0 if you’ve only got major versioning set). So when I’d finally regained consciousness and come to terms with what I believe is a major flaw in the product (isn’t version history supposed to be a big part of its document management capabilities?!?!?!) I decided to park this particular issue and do something else……

Unfortunately it is a pressing requirement, so I have returned to try and find a solution. I feel I should point out at this stage that this is all part of a beautifully crafted K2 workflow solution, so I have to fit the solution in with that. And with some help from your friend and mine, Google, I quickly found I wasn’t the only person facing this problem. I found this post by ‘dink’ a useful starting point, and it gives some background on how SharePoint handles its versions.

http://www.sharepointblogs.com/dez/archive/2007/11/30/moving-copying-documents-between-libraries-with-metadata-including-version-history.aspx

I have started my solution based on the code example given, but need to tidy it up tomorrow, and will report back in due course. I think there are some optimisations to be made (such as handling the version number doesn’t need to be so protracted), but as I say I will post some of my code later.

Si

InfoPath form security privilege errors

Posted in InfoPath with tags , on February 19, 2008 by Si

Came across the following error message while doing some InfoPath stuff in the office last week:

Insufficient Security privilege. The form cannot be opened because it requests domain security level and is only allowed restricted security level.

What was unusual was that some people got the error, whilst others didn’t, although we all had the same privileges on the server (we checked and double checked that one!). After some fumbling around in the various form options, getting nowhere, we came across the following resolution:

Delete your temporary internet files (include all off-line content as well).

Strange, but true – it worked.

(here’s the MS KB article: http://support.microsoft.com/kb/930892)

Si

Hello world!

Posted in Uncategorized on February 18, 2008 by Si

Aaaaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhh! I have finally come crashing and screaming into the modern age with a proper blog, not like the half-hearted attempt I tried before and gave up with because it was too much effort. After much disappointment with other blogs being already taken, I have settled with this. Almost guaranteed to be in my bookmarks as its not the most obvious of addresses. Whether it makes it into your bookmarks remains to be seen……………………

Si