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:
Sweetness! This has to be one of the easiest things I've ever implemented in SharePoint.
Thanks!
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!
Post a Comment