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 created a web scoped feature. In FeatureActivated method I try to GetLimitedWebPartManager from default.aspx file. But the web has not been created yet and default.aspx does not exists.

share|improve this question
    
Do you add default.aspx through a module? –  eirikb Sep 27 '12 at 8:24
    
No I have my own Web Tamplates which inherit from Team site and I use the default.aspx which is defined in onet.xml and the feature has been added to onet.xml under webfeatures, so when it activates the default.aspx not exists –  Medes Sep 27 '12 at 8:48

2 Answers 2

up vote 2 down vote accepted

The best solution is to move to provisioning of Default.aspx into a Feature and then activate that feature prior to the feature adding the web part.

If that's not an option then you can use the following pattern which is common when changing MySites:

  1. Create an additional Feature which adds a control to AdditionalPageHead as a Delegate Control
  2. In that control check if the Feature adding/changing the web part needs to be activated, if it does activate it and redirect back to the page again.

This is required due the sequence of provisioning sites which is:

  1. Create the url for the site
  2. Provision the GLOBAL onet.xml
  3. If new Site Collection activate in order
  4. If new Site Collection activate Site Collection scoped stapled features in random order
  5. Activate in order
  6. Activate Site scoped stapled features in random order
  7. Create list instances defined in onet.xml
  8. Create modules defined in onet.xml
share|improve this answer
    
But I don't want to replace anything. What I want to do is changing the view of a ListViewWebPart. which has been adde in onet.xml like this:<View List="Lists/MyList" BaseViewID="1" WebPartZoneID="Left" WebPartOrder="1" /> but as you know it adds a hidden view which will be default first time. I want to edit the View. –  Medes Sep 27 '12 at 9:26
    
If you create the ListDefinition you can change that view in there. But if not then the steps above are required due to the sequence of Site provisioning. –  Per Jakobsen Sep 27 '12 at 10:19
    
Thanks, Yes I created ListDefinition and add my view to it with another baseviewid and removed all other views. now it works like a charm. it is what I wanted. –  Medes Sep 27 '12 at 10:30

As far as I understand, you want to execute a piece of code in your default.aspx page when a feature is activated. As you said, since the page is not loaded on this event, you won't be able to get to it.

The best way would be to think of adding a custom master page when the feature is activated. The custom master page should have a delegate control attached to it, which internally has the piece of code which you have in your default.aspx. As you know that master page gets loaded all the time, the piece of code in your delegate control will fire up for each page refresh. So, check to execute the code when and where required, just one time.

Hope I have understood your problem correctly. Good Luck ...

share|improve this answer
    
No, sorry it was my mistake I didn't explain clearly. what I want to do is. When the feature is activated get SPLimitedWebPartManager by calling web.GetLimitedWebPartManager("default.aspx", System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared) and try to change the view of a ListViewWebpart, but default.aspx not exists becuase I have added the feature to the onet.xml under webFeatures element and it activates to early. –  Medes Sep 27 '12 at 9:13

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.