{"id":1227,"date":"2012-11-09T20:14:06","date_gmt":"2012-11-09T20:14:06","guid":{"rendered":"http:\/\/www.stuartroberts.net\/?p=1227"},"modified":"2012-11-15T19:11:49","modified_gmt":"2012-11-15T19:11:49","slug":"quick-tip-13","status":"publish","type":"post","link":"http:\/\/www.stuartroberts.net\/index.php\/2012\/11\/09\/quick-tip-13\/","title":{"rendered":"Handling Long Operations"},"content":{"rendered":"<p><strong>SharePoint Short #13<\/strong><\/p>\n<p>Got some code that may take a while to complete?  Good idea to let the user know they may have to wait a while, so put your code within the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/microsoft.sharepoint.splongoperation(v=office.12).aspx\" title=\"SPLongOperation Class\" target=\"_blank\">SPLongOperation<\/a> block, as shown below, and it&#8217;s problem solved.<\/p>\n<pre lang=\"csharp\">\r\nusing(SPLongOperation longOperation = new SPLongOperation(Page))\r\n{\r\n    longOperation.LeadingHTML = \"Please wait while the operation completes...\";\r\n    longOperation.Begin();\r\n\r\n    try\r\n    {\r\n        \/\/ Operations that may take a while to complete...\r\n    }\r\n    finally\r\n    {\r\n        longOperation.End(\"somepage.aspx\", SPRedirectFlags.Static | SPRedirectFlags.RelativeToLayoutsPage | SPRedirectFlags.Trusted, System.Web.HttpContext.Current, string.Empty);\r\n    }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>SharePoint Short #13 Got some code that may take a while to complete? Good idea to let the user know they may have to wait a while, so put your code within the SPLongOperation block, as shown below, and it&#8217;s &hellip; <a href=\"http:\/\/www.stuartroberts.net\/index.php\/2012\/11\/09\/quick-tip-13\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":[]},"categories":[44],"tags":[45],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/plx2I-jN","_links":{"self":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1227"}],"collection":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/comments?post=1227"}],"version-history":[{"count":5,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1227\/revisions"}],"predecessor-version":[{"id":1261,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1227\/revisions\/1261"}],"wp:attachment":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/media?parent=1227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/categories?post=1227"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/tags?post=1227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}