Thursday, May 29, 2008

SharePoint Spin Wheel “Operation in Progress”

Using Custom programming within SharePoint always takes time to execute and create a issue with impatient client. Client always think that we have not done a good job with coding so it will take a long time. Some time if some long operation is going on like creation of site or something like that then 3rd person thinks like process is hang up.
So what we need to do is that do some indication screen like “In progress”.



And the exciting news is SharePoint is providing built in function for “Operation in Progress” spinning wheel and object is called as “SPLongOperation”.

You can use this object in various places like creating a custom SharePoint site, setting up properties, creating a Project in Different server, calling a web services, updating/adding multiple items in SharePoint…. Etc.

Check the following snippet which is used in webpart.


void Button1_Click(object sender, EventArgs e)
{
SPLongOperation longoperation = new SPLongOperation(this.Page)

longoperation.LeadingHTML = "Leading HTML shows here";
longoperation.TrailingHTML = "Trailing HTML will be displayed here";
longoperation.Begin();

// Code which will take time…

longoperation.End(strURL);
}

How it works?

SPLongOperation has LeadingHTML properties which Shows message in Bold and TrailingHTML property shoes second a little large message.
Begin () method starts spinning wheel at a time on the same page.
You can find in debug mode that after execution of that line wheel appear on the screen.
All the code execute under wheel until you call End() function.
The End() method will take URL as parameter and will redirect to your desired page.

Special thanks to Brian Caauwe for his post which guide me to solve my headache.

2 comments:

Anonymous said...

Sweetness! This has to be one of the easiest things I've ever implemented in SharePoint.

Thanks!

dotNetFollower said...

Hello!
Nice article, but it doesn't take into account ThreadAbortException, which is sometimes thrown. I have a similar article in my blog and I explained the reason of ThreadAbortException. Unlike this post, my article is concerning SP2007, but I believe, that SPLongOperation wasn't changed thoroughly. The article is here - http://dotnetfollower.com/wordpress/2011/08/sharepoint-how-to-use-splongoperation/
Thanks!




Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com