I have a feature that upgrades and updates an existing site to a new and improved version of that site. One of the tasks of the feature is to upgrade existing data in the site. For simple test/dev sites the process is quick enough, but some existing sites have loads of data. The feature activation takes a long time when process all the existing data on the site.

Can I use SPLongOperation in a FeatureActivating-method? What page should I redirect to?

I'm using moss

2 Answers 2


Feature activation could be performed two completely different ways:

  1. Through GUI - in this case you have HttpContext, SPContext and all other stuff ready for you and SPLongOperation will work
  2. By using stsadm or PowerShell - in this case you don't have anything of above and obviously SPLongOperation will not work (DotPeek also shows it depends on HttpContext).

You can determine which scenario you're running simply by comparing HttpContext.Current to null.

For the stsadm/PS scenario, you can consider creating a separate timer job or something like this. For GUI, you are able to use SPLongOperation and redirect to the "Site Features" or "Site Collection Features" page after it finishes, depending of which scope you're using for the feature. The redirection url will be /_layouts/ManageFeatures.aspx?Scope=Web or /_layouts/ManageFeatures.aspx?Scope=Site correspondingly.

P.S. I don't have any real experience of using SPLongOperation from within feature receiver, but I have experience of determining the GUI/stsadm from within feature for some other purposes.

  • 1
    By the way, I've found a question from moontear where he successfully uses SPLongOperation within a FeatureActivated receiver. You can find it interesting, because the question covers some error handling specifics: sharepoint.stackexchange.com/questions/14694/… May 3, 2012 at 9:15
  • Thanks! It works very nice. I do check if the current context is valid, in order to differentiate between the GUI and PowerShell/stsadm. And i make use of wss.boman.biz/Lists/Posts/Post.aspx?ID=19 to provide feedback about the progress.
    – Dribbel
    May 3, 2012 at 10:08

But you have this option also:

    delegate(SPLongOperation longOperation)
        // Do something that takes a long time to complete.
        ContentTypeMapping CTMapping = new ContentTypeMapping(site);
        CTMapping.MapContentTypesToWorkspace(null, web);

        // Inform the server that the work is done
        // and that the page used to indicate progress
        // is no longer needed.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.