开发者

Use of SPStatefulLongOperation

Can someone give me an example of the use of SPStatefulLongOperati开发者_StackOverflowon? It's very poorly documented.


Here's an example of code I've just used. It applies a ThmxTheme (selectedTheme) to all SPWebs in an SPSite (site).

SPStatefulLongOperation.Begin(
    "Applying theme to sites.",
    "<span id='trailingSpan'></span>",
    (op) =>
    {
        op.Run((opState) =>
        {
            for (int i = 0; i < site.AllWebs.Count; i++)
            {
                // Update status.
                opState.Status = String.Format(
                    "<script type='text/javascript'>document.all.item('trailingSpan').innerText = '{0} ({1} of {2})';</script>",
                    site.AllWebs[i].Title,
                    i + 1,
                    site.AllWebs.Count);

                // Set the theme.
                selectedTheme.ApplyTo(site.AllWebs[i], true);
            }
    });

    op.End(System.Web.HttpContext.Current.Request.UrlReferrer.ToString());
});

Note that the current value of opState.State is appended to the client's HTML (via HttpContext.Current.Response.Write and .Flush) every second. Thus you don't want to send any status message directly; you want to send some JavaScript that will update an existing status element on the page. (Here, the trailingSpan element.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜