Show “Operation In Progress” spinning wheel in custom code
While doing custom coding in SharePoint if you have any long running operations(like creation of site) which take some significant time to complete then you always want to give a hint to the end user to be patient and that the operation is in progress and it is not in the hung state.
SharePoint does it smartly by showing the smart spinner.
While coding custom stuff I always wanted to show the same spinner as that would be consistent with the out of box SharePoint behavior.
Initially I used to(and saw many others too) doing it by embedding some JavaScript to load the image, until I stumbled upon this.
It was exciting to see that this is there as a built in function - "SPLongOperation".
Below is the way we can use this in code :
using (SPLongOperation longOperation = new SPLongOperation(this.Page))
{
longOperation.LeadingHTML = "Put Leading HTML here";
longOperation.TrailingHTML = "Put Trailing HTML here";
longOperation.Begin();
// Code that takes time to complete…
longOperation.End(strURL);
}
Nice little piece that Microsoft added :)
5 comments:
nice to see you blog your learnings!!keep it up bro!!
Hi,
I just saw your blog url in one of your questions you posted in MSDN regarding
"Open in new window does not work when SSRS report is hosted in SharePoint".
I too am having the same error. Could you resolve it? If yes, can you please let me know how.
Hello!
I have a similar article in my blog. Additionally I explained the reason of ThreadAbortException, which is sometimes thrown. The article is here - http://dotnetfollower.com/wordpress/2011/08/sharepoint-how-to-use-splongoperation/
Thanks!
This is quite simple development work out once you comprehend how the LongOperation class is adjusting the browse. This has saved lot of time as I was not knowing that this could be done in such a simple way.
Hi..nice tips. Thanks
Post a Comment