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

3 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

  3. Hello!
    Nice post, but SPLongOperation.End doesn’t call Response.Redirect (usual for ASP.NET), it uses Response.End directly and after that ThreadAbortException is thrown. Redirection is accomplished through special JavaScript, which is added to web page right after SPLongOperation.End is invoked. I have mentioned about this fact in my blog post here – http://dotnetfollower.com/wordpress/2011/08/sharepoint-how-to-use-splongoperation/.
    Thanks!

    Comment by dotNetFollower — 11 August, 2011 @ 8:45 pm


RSS feed for comments on this post. TrackBack URI

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: