Monday, April 27, 2015

SharePoint – Back to basics – SPLongOperation for lengthy operations

We have many hidden features in SharePoint in look and feel in Out of Box as well as custom. SPLongOperation One of the hidden feature in custom coding side. This feature exists from SharePoint but many of the users may not be aware of this. SPLongOpearation allows us to inform end users on processing screen while operating lengthy operations like moving documents from one site other, deleting sites etc... And at the end we can have options to close/ redirect the page.

Here is the sample code on usage of SPLongOperation,

               try{
                              using (SPLongOperation longOpearation = new SPLongOperation(this.Page))
                              {
                                             longOpearation.LeadingHTML = "Title of the long operation";//title message
                                             longOpearation.TrailingHTML = "this will take few sec”//sub message
                                              longOpearation.Begin();
                                             //Code start
                                             //Write the code that to be processed in long operation
                                             //code ends
                                               HttpContext context = HttpContext.Current;
                                             if (context.Request.QueryString["IsDlg"] != null)
                                             {
                                                            context.Response.Write("<script type='text/javascript'>window.frameElement.commitPopup();</script>");
                                                            context.Response.Flush();
                                                            context.Response.End();
                                              }
                                              else
                                              {
                                                             string url = SPContext.Current.Web.Url;
 longOpearation.End(url, SPRedirectFlags.CheckUrl, context, string.Empty);
                                             }

                              }
               }
               catch (Exception ex)
              {
                              SPUtility.TransferToErrorPage(ex.ToString());//transfores us to the error page with error message
               }

In the Begin and End methods for long operation we can have different overloaded methods. By using SPLongOperation.Begin method (String, String, SPLongOperation.BeginOperation) method we can pass title and sub message. Here in the script end method, iam passing redirection URL and checking flags and current context. For more details, here is the full description in msdn.



Share this

11 Responses to "SharePoint – Back to basics – SPLongOperation for lengthy operations"

  1. There are lots of information about latest technology and how to get trained in them, like this have spread around the web, but this is a unique one according to me. The strategy you have updated here will make me to get trained in future technologies. By the way you are running a great blog. Thanks for sharing this.
    Java training in chennai

    ReplyDelete


  2. This information is impressive; I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic.

    Digital Marketing Company in Chennai

    Digital Marketing Services in Chennai

    ReplyDelete
  3. I really enjoyed while reading your article, the information you have delivered in this post was damn good. Keep sharing your post with efficient news.
    Regards,
    J2EE Training in Chennai|JAVA Training Chennai

    ReplyDelete
  4. Good work for wonderful the article share.It read go for very interesting.

    Hadoop Training in Chennai
    Hadoop Training Chennai

    ReplyDelete

  5. For management and troubleshooting of enormous databases, corporation’s square measure searching for qualified and licensed dispersions Hadoop experts for the duty. Hadoop Training in Chennai | Hadoop Training Chennai

    ReplyDelete
  6. This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharng this information,this is useful to me...
    Android training in chennai
    Ios training in chennai

    ReplyDelete

  7. Thanks for posting useful information.You have provided an nice article, Thank you very much for this one. And i hope this will be useful for many people.. and i am waiting for your next post keep on updating these kinds of knowledgeable things...Really it was an awesome article...very interesting to read..please sharing like this information......
    Web Design Development Company
    Mobile App Development Company

    ReplyDelete
  8. There are lots of information about technology and how to get trained in them, I really Like your Post.Thanks for the sharing.
    Web Designing training in noida | SAS Summer Training in Noida | Java Training in Noida

    ReplyDelete
  9. Thanks for sharing this information and keep updating us. This is informative and really useful for me.

    JAVA Training Company in Delhi | Animation Multimedia Training in Delhi | CAD Training Center In Delhi

    ReplyDelete

  10. This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharng this information,this is useful to me...
    Android training in chennai
    Ios training in chennai

    ReplyDelete