September 10, 2008

How to display the SharePoint waiting page when doing long operations in your code

Displaying the SharePoint waiting page with the rotating gear image is easy. The Microsoft.SharePoint namespace provides the SPLongOperation class to play the trick.

As this class implements the IDisposable interface, the best is to use a using statement like in the following example:

void buttonProcess_Click(object sender, EventArgs e)
    using (SPLongOperation operation = new SPLongOperation(this.Page))
        // Define the url to be redirected after the long operation
        string url = "http://myserver/myotherpage.aspx";
        operation.LeadingHTML = "Please wait...";
        operation.TrailingHTML = "Description...";
        //Place here the code that takes a long time to be executed

MSDN link:

No comments: