SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What's the best method for adding an XsltListViewWebPart to a site definition's default.aspx?

I've tried to add one to the definition's default.aspx declaratively by copying the XML from an existing page, but there are a number of references to view and list guids which I won't have until the site is provisioned. The alternative was to programmatically add to the default.aspx via a site provisioned or feature activated event handler, but it's impossible to get a reference to the default.aspx until the site has been created.

share|improve this question

There is a WebProvisioned event receiver you can how hook into in 2010.

This executes once the pages are loaded, have a looksie at this:

share|improve this answer

Is the list the WebPart needs to look at is also provisioned as part of the Site Definition?

If so, rather than using the AllUsersWebPart element in the definition, you can use the View element.

Some of the out of the box site definitions do this (Like Blog) so you can look at them for a starting point.

share|improve this answer

Your Answer


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.