SPLongOperation allows us to inform end users on processing screen while operating lengthy operations like moving documents from one site other, deleting sites etc... And at the end we can have options to close/ redirect the page.
Here is the sample code on usage of SPLongOperation,
using (SPLongOperation longOpearation = new SPLongOperation(this.Page))
longOpearation.LeadingHTML = "Title of the long operation";//title message
longOpearation.TrailingHTML = "this will take few sec”//sub message
//Write the code that to be processed in long operation
HttpContext context = HttpContext.Current;
if (context.Request.QueryString["IsDlg"] != null)
string url = SPContext.Current.Web.Url;
longOpearation.End(url, SPRedirectFlags.CheckUrl, context, string.Empty);
catch (Exception ex)
SPUtility.TransferToErrorPage(ex.ToString());//transferes us to the error page with error message
In the Begin and End methods for long operation we can have different overloaded methods. By using SPLongOperation.Begin method (String, String, SPLongOperation.BeginOperation) method we can pass title and sub message. Here in the script end method, iam passing redirection URL and checking flags and current context.