Displaying SharePoint 2010 “Processing” page during your long running custom operations

Way since MOSS you have seen similar page to below, this is SharePoint 2010 abviously:

Usually when you create a site collection or apply changes or anything else that takes time for that matter. Now, did you know that it’s very easy to get 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 couple of long running operations and want “Processing” page to show up and when completed – come back to my page where the UserControlWebpart is on. 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))
//… your code ..
operation.End(comeBackUrl, Microsoft.SharePoint.Utilities.SPRedirectFlags.DoNotEncodeUrl, HttpContext.Current, null);

Hope this helps!

About the author: Yaroslav Pentsarskyy