Overview
When you are performing out of the box operations in SharePoint 2010 normally in Central Administration you will get a nice loading screen from SharePoint with an animated loading gif. Have you ever wondered how you can use this in your own SharePoint Solution? I have been doing SharePoint for a while now and only recently discovered the SPLongOperation method and it is quite the little gem.
|
SPLongOperation.BeginOperation beginOperation = null; if (beginOperation == null) { beginOperation = delegate(SPLongOperation longOperation) { // Long running code here .. longOperation.End("settings.aspx", SPRedirectFlags.RelativeToLayoutsPage, HttpContext.Current, null); }; } SPLongOperation.Begin(beginOperation); |
I have been writing a site provisioning service recently and have used the above code to help provide the end users some feedback while a
new site collection is being created. Only a couple of lines of code but it transformed the solution.
Want to change the text that is displayed in the loading screen? No problem.
|
// BEGIN SPLongOperation SPLongOperation longoperation = new SPLongOperation(this.Page); longoperation.LeadingHTML = "<div><h2>This is the main Title</h2></div>"; longoperation.TrailingHTML = "<div><h3>This is the second line of text underneath</h3></div>"; longoperation.Begin(); // long running code here // END SPLongOperation longoperation.End(Customers.DefaultViewUrl, Microsoft.SharePoint.Utilities.SPRedirectFlags.Default, this.Context, ""); |
This will change the text on the page to reflect your specific requirements.

Branding the Loading Page
Do you want to match the loading page to your corporate colour scheme? No problem. Below is the output of the page in raw html.
|
<body onload="setGearPageFocus();gotoNextPage();" class="s4-simple-gearpage"> <div id="GearPage"> <div id="s4-simple-card" class="s4-simple-gearpage"> <div id="s4-simple-card-content"> <h1> <a id="gearsImageLink" href="javascript:;" onclick="hideGears();" title="This animation indicates the operation is in progress. Click to remove this animated image." > <img id="gearsImage" alt="This animation indicates the operation is in progress. Click to remove this animated image." src="/_layouts/images/gears_anv4.gif" style="width:24px; height:24px; font-size:0px;" align="absmiddle" /> </a> Processing... </h1> <div> Life In SharePoint Long Operation Demo </div> <div> <br /><br />This is a custom long operation text </div> </div> </div> </div> </body> |
As you can see the markup is very simple. What you can then do is create a new CSS style sheet and inject the reference to it in the LeadingHTML property as the property is not escaped.
|
longoperation.LeadingHTML = "<link rel='stylesheet' href='/_layouts/LifeInSharePoint/LongOperation.css' type='text/css' />Life In SharePoint Long Operation Demo"; |
This will then enable you to customize the page as you need to changing background colours, fonts images etc. This is the kind of result that you will get.

Do download a working solution with branding included please use the link below.
LISP.LongOperationDemo.zip