El Blanco's Office 2007 Blog

Thursday, September 13, 2007

An Issue with SPLongOperation

Two posts in one day ?! Not like me normally, but this one has been BUGGING me for absolutely ages and I've just solved it, so thought I'd share the solution here and now in case this had been bugging anyone else the same way it's been bugging me . . .

As most of you know, if you have some functionality on an application page that takes a while to execute you can wrap the functionality inside an SPLongOperation as shown below:

protected void btnCreate_Click(object sender, EventArgs e)
    using (SPLongOperation op = new SPLongOperation(this.Page);
        op.LeadingHTML = "Please wait while XXX completes."}
        // do something that takes a fair old while . . .

Basically what happens is you get the nice SharePoint spinny thing (wonder if there's a proper name for this ?!) displayed with your "Please wait while XXX completes" message while the operation is in progress i.e. between the calls to op.Begin() and op.End(). Upon the call to op.End() the browser is then redirected to the URL you pass into the call.

This was working fine for two of my custom application pages (or so I thought) but on a third application page I was having major issues. When I clicked the button on my application page it was taking a good while before the post back occurred and the SharePoint spinny thing appeared. On my other two application pages it was working fine and was redirecting to the SharePoint spinny thing page almost immediately and displaying my waiting message.

I'd never had time to look into why this was, and it was bugging me bug time, but I found some time today. Basically, in the page directive of the application page causing me issues I had the "SmartNavigation" property set to "true". In the other two application pages I didn't. Simple as that (although it took a fair old while to narrow this down, I can assure you !!). I removed the SmartNavigation property from my page directive and it now works as expected.

I'm not sure why the two don't co-exist nicely (perhaps someone can post a comment and tell me) but I'm just pleased to have solved something that has bugged me for so long. Hopefully if you're experiencing delays in waiting for your SharePoint spinny thing in your application page this will help you out !

Programmatically Activating an InfoPath Form Template

A colleague today asked me whether it was possible to programatically activate an InfoPath form template from the form templates store in Central Administration to a site collection. After much digging around in the MOSS SDK I couldn't really find anything until I stumbled across the forms services SDK online. Using a combination of the two I came up with the following which shows how to do this:

Firstly you'll need to add a reference to the Microsoft.Office.InfoPath.Server.dll assembly, which can be found at the following location:

C:\Program Files\Microsoft Office Servers\12.0\Bin

After adding a reference to this assembly you can use the following code fragment to achieve the requirement:

using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.Office.InfoPath.Server.Administration;

SPSite siteCollection = ...
SPServiceCollection services = SPFarm.Local.Services;

foreach (SPService svc in services)
    FormsService fs = svc as FormsService;
    if (fs != null)
        foreach (FormTemplate ft in fs.FormTemplates)
            if (ft.Name == "<the name you want>")

Hope this helps !

Tuesday, September 04, 2007

New Release of the Event Receivers Manager

Thanks to everyone who has sent me comments. Today I've uploaded v1.1 of the Event Receivers Manager to my CodePlex site (http://www.codeplex.com/elblanco) which fixes the issues related to the breadcrumb controls on the application pages. I'd like to thank Karine Bosch of U2U for helping me out with this by sending me sample code and pointing me to a useful article by Mikhail Dikov – thanks Karine!

Once you've downloaded the new release you can install it as previously described, or if you already have the solution installed simply upgrade it with the following command:

stsadm –o upgradesolution –name BlancoWorld.EventReceiversManager.wsp –filename BlancoWorld.EventReceiversManager.wsp –immediate -allowGacDeployment

People have also reported issues with the solution not working on WSS 3.0. I tested the solution on a vanilla WSS 3.0 install and everything appears to be working fine, and there's no reason why it shouldn't as there's nothing in the solution that is MOSS-specific. People are reporting that the "Event Receivers" link is not displaying in the list settings page in WSS. The only thing I can think of is that you haven't activated the Site Collection feature as this is what puts the link in place. Running the two stsadm commands on the command line only adds and deploys the solution, which installs the feature – it doesn't activate the feature. Hope this solves some people's issues, if not then please get in touch again with more details and I'll try and resolve any problems.