Subscribe:

Labels

Wednesday, February 8, 2012

sharepoint long Operation example using object model code

.  In the following example I have use LongOperation using sharepoint Splongoperation class. I have created 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);
    }
}
Enhanced by Zemanta

No comments:

Post a Comment