SharePoint Internals – Hristo Pavlov’s Blog

16 June, 2008

Show an “Operation in Progress” page from your code

Filed under: SharePoint — Tags: , — hristopavlov @ 11:42 am

You can also show the nice animated message that SharePoint shows on long operations from your web parts and web controls as the one below. This is actually very easy to be done.

You just need to use the SPLongOperation class. Specify the custom message to be shown, then call Begin() method to show the “Operation in Progress” page and then start doing your long operation stuff. When ready you call End() passing a URL to be redirected to. If an exception occurs you may also redirect to the standard error page as shown in the code below:

try

{

    using (SPLongOperation ctx = new SPLongOperation(this.Page))

    {

        ctx.LeadingHTML = “Please wait while your operation is being executed.”;

        ctx.TrailingHTML = “Your current operation is currently being executed. Please be patient. Blah blah blah.”;

        ctx.Begin();

 

        MyLongRunningOperation();

        ctx.End(SPContext.Current.Web.Url);

    }

}

catch (ThreadAbortException) { /* Thrown when redirected */}

catch (Exception ex)

{

    SPUtility.TransferToErrorPage(ex.ToString());

}

Because when an HTTP redirection is done from ASP.NET a ThreadAbortException is thrown, we have to catch this exception in its own catch block and ignore it.

For more info check the MSDN documentation of the SPLongOperation class here: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splongoperation.aspx

2 Comments »

  1. [...] Show an “Operation in Progress” page from your code [...]

    Pingback by Links (6/17/2008) « Steve Pietrek - Everything SharePoint — 18 June, 2008 @ 1:36 am

  2. [...] 29, 2008 Here’s an interesting post on how to show an “Operation in Progress” page in SharePoint from [...]

    Pingback by Showing Progress in SharePoint via Code « // T3chNicaL.LEad — 29 June, 2008 @ 8:04 pm


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.