SharePoint Dragons

Nikander & Margriet on SharePoint

Long operation in progress

Sometimes, there are operations on a SharePoint application page or a web part that take a long time to complete. The best thing to do is to reuse the In Progress animated picture used by SharePoint itself, as shown in the next picture:

This can be accomplished easily by using the SPLongOperation class of the Microsoft.SharePoint namespace. It sets the web page image to the image used by the server to indicate a lengthy operation (typically, an animated image with associated text). The code goes something like this (taken from http://social.technet.microsoft.com/Forums/en-US/sharepoint2010general/thread/6d40adc2-0a61-448b-81ba-69ec7c4e5144):

using (SPLongOperation objLongOperations = new SPLongOperation(this.Page))
 
{
objLongOperations.LeadingHTML =”Processing request”;
objLongOperations.TrailingHTML = “Please wait while the request is being processed…”;
objLongOperations.Begin();
 
//Write your code here
 
System.Threading.Thread.Sleep(25000);//added to show the processing screen. Nor required in actual implementation
objLongOperations.End(this.Page.Request.Url.ToString());
 
}

Check this blog post for more information: http://peterheibrink.wordpress.com/2009/09/07/splongoperation/

Leave a Reply

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

WordPress.com Logo

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

Facebook photo

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

Connecting to %s

%d bloggers like this: