原链接: http://hristopavlov.wordpress.com/2008/06/16/show-an-operation-in-progress-page-from-your-code/
说明:用代码实现Sharepoint里面的加载效果, 在一些操作如创建site时,需要等待比较长时间的时候, sharepoint就会出现 ‘Operation in Progress’ 效果
用代码实现这个效果,让你的页面也向sharepoint一样效果!
你只需要使用SPLongOperation类。指定要显示自定义消息,然后调用begin()方法,以示“Operation in Progress“页面,然后开始做你的长期操作的东西。当准备好你调用End() 方法 传递一个被重定向到的URL。如果发生异常,你也可以重定向到标准错误页,如下代码所示:
因为当一个HTTP重定向是从ASP.NET做一个ThreadAbortException被抛出,我们必须抓住在自己的块捕获此异常并忽略它。
try
{
using (SPLongOperation ctx = new SPLongOperation(this.Page))
{
ctx.LeadingHTML = “Please wait while your operation is being executed.”;
ctx.TrailingHTML = “Your current operation is currently being executed. Please be patient. Blah blah blah.”;
//开始
ctx.Begin();
//你的操作方法
MyLongRunningOperation();
//操作完毕后需要跳转到的页面
ctx.End(SPContext.Current.Web.Url);
}
}
catch (ThreadAbortException) { /* Thrown when redirected */}
catch (Exception ex)
{
//跳转到sharepoint的错误页面
SPUtility.TransferToErrorPage(ex.ToString());
}