Sunday, 7 April 2013


SharePoint SPLongOperation

Sometimes the actions triggered by users can take a while to process. This can for example happen when you create a site collection. At that time you:

  • Don’t want your users to continue clicking on the button, the action should finish first. With the example of the creation of a site collection, you don’t want two attempts of creating a site collection with the same URL.
  • Users must be made aware that the action might take a while and have the idea something is really happening behind the scenes.

 Microsoft provided some nice ways to have implement those long running operations. One is SPLongOperation which shows the user the “Operation in Progress” screen and it is actually pretty easy to implement.

Here is the way to use this. 


?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
protected void btnSubmit_Click(object sender, EventArgs e)
 {
 
     using (SPLongOperation longOperation = new SPLongOperation(this.Page))
     {
         // Provide the text displayed in bold
         longOperation.LeadingHTML = "";
    // Provide the normal formatted text
         longOperation.TrailingHTML = "Please wait your changes are processed";

         longOperation.Begin();
   
         
         string URL = SPContext.Current.Web.Url + "/Pages/OperationDone.aspx";
         longOperation.End(URL);
     }
 }
This will give you a screen like below : 


Thank you !! 

No comments:

Post a Comment