SharePoint中长时间等待页面的自定义
我们可以通过SharePoint中的SPLongOperation类的方法,实现自定义长时间等待的页面。
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());
}
欲了解更多信息检查MSDN文档 SPLongOperation类: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splongoperation.aspx
相关资料:
You can use this delegate method with the static SPLongOperation.Begin(SPLongOperation.BeginOperation) method, as shown in the following example:
SPLongOperation.Begin(
delegate(SPLongOperation longOperation)
{
// Do something that takes a long time to complete.
// Inform the server that the work is done
// and that the page used to indicate progress
// is no longer needed.
longOperation.End("default.aspx");
}
);