Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer
    
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/… –  Andrey Markeev May 3 '12 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 '12 at 10:08
add comment

But you have this option also:

SPLongOperation.Begin(
    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.
        longOperation.End(site.Url);
    });

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splongoperation.beginoperation(v=office.14).aspx

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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