Sue Hernandez's SharePoint Blog

SharePoint and Related Stuff

SharePoint 2007: Long Running Operations – timeout

I have recently been challenged with a web part in v3 (MOSS) that has to iterate through a bunch of users’ permissions in v2 (WSS 2.0), which takes forever and always seems to time out.  I found 2 items that I would like to share with you, one of which takes care of processes that run a long time but don’t time out, and one of which that handles an operation so long it will time out.


The first method, which doesn’t solve timeout issues, but does provide feedback for long operations, is via the SPLongOperation class.

Gears Page in SharePoint

Gears Page in SharePoint

 Basically, what you do is instantiate an SPLongOperation object, set its LeadingHTML and TrailingHTML properties, and then wrap it arount a long running process.  You would use in a web part as follows:

In the class, declare an SPLongOperation object:

SPLongOperation longRunningJob;

In the CreateChildControls method, instantiate the object to a new instance and set its parameters:

longRunningJob = new SPLongOperation(this.Page);
longRunningJob.LeadingHTML = "This is a bold description of my operation";
longRunningJob.TrailingHTML = "This is a normal or sub-description of my operation";

Where-ever you have your long running code, “wrap” the SPLongOperation object around it:

// Some URL to redirect to once the processing has completed
string url = SPContext.Current.Web.Url;
// Some long processing here


 The second method is to inherit from the LongRunningOperationJob which can be found in the Microsoft.SharePoint.Publishing dll which you can find in your Program Files (C:\Program Files\Microsoft Office Servers\12.0\Bin for example).  You override the DoWork method to actually complete your long running task.  Take for example the following instance of a class inheriting from LongRunningOperationJob:

public class UpdateUsersPermissionsJob : LongRunningOperationJob
  private SPWeb web;
  private string currentlyLoggedInUser;
  UpdateUsersPermissionsJob(SPWeb web, string currentlyLoggedInUser)
    _web = web;
    _currentlyLoggedInUser = currentlyLoggedInUser;
  public override void DoWork()
      // Some Long Processing here
      foreach(SPUser user in web.Site.AllUsers)
        // Do some operation
        this.StatusDescription = "Updating user " + user.Login;
    catch (Exception ex)

You would call this operation from inside your code where you want to actually perform the action:

private void cmdSubmit_Click(object sender, EventArgs e)
  SPWeb web = SPContext.Current.Web;
  string user = SPContext.Current.Web.CurrentUser.Login;
  UpdateUsersPermissionsJob job = new UpdateUsersPermissionsJob(web, user);
  job.Title = "Updating users for web " + web.Title;
  job.WaitMessage = "Please wait while the users are updated...";
  job.RedirectWhenFinished = false;
  job.UserCanCancel = false;
  job.TotalOperationsToBePerformed = web.Site.AllUsers.Count;
  job.GearsImageUrl = "~/_layouts/images/gears_an.gif";
  job.MillisecondsToWaitForFinish = 2500;

This brings you to a page that will show a progress bar and the message you set as the WaitMessage.

In Progress page

In Progress bar for LongRunningOperationJob Status Page

 Check out the reference links for more code and more examples.


6 responses to “SharePoint 2007: Long Running Operations – timeout

  1. Jeff Barton May 20, 2010 at 3:51 am

    Any ideas on how to accomplish something similar in WSS? This solution would work perfectly if I was using MOSS…

    Any help would be appreciated!

  2. Susan Hernandez July 1, 2010 at 5:04 pm

    So sorry I missed this comment for so long. And no, I’m not aware of any way to do this in WSS. If I find something I’ll post it here.

  3. Peter Riad January 27, 2011 at 8:20 am

    Thanks so much for highlighting such great classes, you really save me a lot of time.

  4. guruprasadmarathe February 15, 2013 at 10:10 am

    i also tried to user first scenario what u have said.. using splong, but after one hour that page went to page cannot be displayed mode. my httpresponsetimeour time is 3600 1 hour. so SPLongOperation does not worked as expected. my code will take atleast 2 hours.. what to do?? shall i try your second approach?

  5. Susan Hernandez February 15, 2013 at 10:11 pm

    I would definitely in your situation look in to inheriting from LongRunningOperationJob as in my second approach, yes. I don’t know even if that will handle a 2 hour job, but since it is a job in the background with just a status page that periodically refreshes, I don’t see why not. You don’t have to sit on the status page for the whole 2 hours do you? Just check on it periodically.

  6. Intekhab October 23, 2014 at 9:39 pm

    I am using the same as given in the same code but when I am calling the updatestatus method , I am getting Site with 00000000 id is not found (file not found exception). Do I need to do something extra?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: