SPLongOperation - SharePoint Spin Wheel

For those of you that have created applications on the SharePoint platform, you may have some code that takes a while to run in your environment, while the end user is staring at the screen wondering when/if the process is complete.  If only you could create a status page that lets the user know their process is running.  Maybe you want to find out how to utilize the SharePoint “Operation in Progress” spin wheel.  The good news is, there is a class built into the SharePoint object model called SPLongOperation.

 

I have used this class on various occasions when needing to programmatically create sites and modify properties to various object.  In the following example I have a custom Web Part that has a button on it to create a site where I need perform some custom actions.

 

        void _createButton_Click(object sender, EventArgs e)

        {

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

            {

                operation.LeadingHTML = "Creating Site";

                operation.TrailingHTML = "Please wait while the project site is being created for " + siteTitle;

                operation.Begin();

 

                SPWeb sub = currentWeb.Webs.Add(siteAbbrev, siteTitle, siteDesc, 1033, "STS#0", false, false);

 

                // Do the rest of my code . . .

               

                operation.End(sub.Url);

            }

        }

 

How the SPLongOperation works is you create a new object of type SPLongOperation then you can change the wording that will be displayed on the screen while the process is running by modifying the LeadingHTML and TrailingHTML properties.  After you have everything ready just kick off the operation using the Begin method.  Once you are in the Begin method, every piece of code you write all happens behind the spin wheel.  And once your code has completed, call the End method and you pass a URL that the user will be re-directed to once your code has completed.  Here is an example page of what it looks like when calling the SPLongOperation class to wrap your code around.

 

SPLongOperation

 

The good thing about using SPLongOperation is it can remove any issues with users being impatient when they think your code has halted, along with giving a consistent look since SharePoint already uses that spin wheel in various places.


Posted 12-20-2007 12:07 PM by Brian Caauwe

Comments

Vedanshu wrote re: SPLongOperation - SharePoint Spin Wheel
on 01-14-2008 4:23 AM

Thanks Brian, Your post was extremely informative and helpful.

Sandeep wrote re: SPLongOperation - SharePoint Spin Wheel
on 01-16-2008 3:37 AM

Thanks a TON. Great post.

Many an Hour wrote re: SPLongOperation - SharePoint Spin Wheel
on 04-28-2008 8:10 AM

Thats great thanks being here there and everywhere with this one. How does the Excel Services Web Part and BDC work to allow for a similar experience on the page?

Inetium, LLC. Site Information