Back to Insights

Using the Processing page in your SharePoint 2010 custom modules

If you have ever worked with MOSS 2007 or SharePoint 2010 you likely remember seeing this page...

long operation

It appears when you create new sites or run any other long-running operations. It's also very easy to have this page displayed during your own long-running operations. Not only that, it will redirect back to your code when it's done with the execution!

Let's say I have a "UserControlWebpart" in my SharePoint solution, and in my "OnLoad" method I call a couple of long-running operations and want the "Processing..." page to show up. When completed, I want to come back to my page where the "UserControlWebpart" is.

Here is all I need to wrap my custom long-running code with:

string comeBackUrl = this.ViewState["__REFERER__"].ToString();
using (SPLongOperation operation = new SPLongOperation(this.Page))
{
 operation.Begin();
 //?.. your code here ?.
 operation.End(comeBackUrl, Microsoft.SharePoint.Utilities.SPRedirectFlags.DoNotEncodeUrl, HttpContext.Current, null);
 }

That's all that you need to do... SharePoint takes care of the rest!

Share