Pages

Subscribe:

Friday, February 3, 2012

SPLongOperation - SharePoint Processing Page

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.

As a SharePoint Developer, you can wrap your lengthy operations code with the SPLongOperation to display the spinning wheel processing screen whenever you are executing long duration code-block to improve the user experience. After invoking SPLongOperation object, you can start and stop the long operation using Begin() and End() methods. Alternatively, you can use the LeadingHTML and TrainingHTML properties to customize the message on the processing screen.
protected void btnProvisionSites_Click(object sender, EventArgs e)
{
    //Long Operation Code
    using (SPLongOperation longOperation = new SPLongOperation(this.Page))
    {
        //Custom Messages on the Spinning Wheel Screen
        longOperation.LeadingHTML = "Provisioning Sites";
        longOperation.TrailingHTML = "Please wait while the sites are being provisioned.";
        //Start the long operation
        longOperation.Begin();
        //Your Long Operation Code Goes Here...
        // e.g. Site provisioning code
        //End the long operation
        string redirectURL = SPContext.Current.Web.Url;
        longOperation.End(redirectURL);
    }
}
Happy Coding...!!!!

1 comments: