I've got a list which has got two views (a list and a calendar view), which are being created when activating a feature containing following view definition for the calendar in the Schema.xml of the ListDefinition.

  <View BaseViewID="1" Type="CALENDAR" DisplayName="All appointments" WebPartZoneID="Main" MobileView="TRUE" Scope="Recursive" SetupPath="pages\viewpage.aspx" Url="AllAppointmentsCalendar.aspx" ImageUrl="/_layouts/images/generic.png">
      <FieldRef Name="StartDate"/>
      <FieldRef Name="EndDate"/>
      <FieldRef Name="Title"/>
      <FieldRef Name="DisplayText" Type="CalendarMonthTitle"/>
      <FieldRef Name="DisplayText" Type="CalendarWeekTitle"/>
      <FieldRef Name="" Type="CalendarWeekLocation"/>
      <FieldRef Name="DisplayText" Type="CalendarDayTitle"/>
      <FieldRef Name="" Type="CalendarDayLocation"/>
          <FieldRef Name="StartDate"/>
          <FieldRef Name="EndDate"/>
          <Value Type="DateTime">
    <Toolbar Type="Standard"/>

Creating this view will create a page containing the calendar at the URL /Lists/Appointments/AllAppointmentsCalendar.aspx

Requirement: Add an additional WebPart to the page created by the view.

To add this additional WebPart I've attached an SPFeatureReceiver and wanted to add it with the WebPartManager in the FeatureActivated method.

Question: How can I get the System.Web.UI.Page instance of the page created while creating the view in order to be able to use it to get the WebPartManager with WebPartManager.GetCurrentWebPartManager(page)?

Or is there another, better approach?


Going to answer my own question. Knowing the page URL, I've been able to retrieve the (limited) web part manager through the SPWeb:

    public override void FeatureActivated(SPFeatureReceiverProperties properties)
            string relativePageUrl = string.Format("Lists/{0}/AllAppointmentsCalendar.aspx",
            SPLimitedWebPartManager limitedWebPartManager =
                ((SPWeb) properties.Feature.Parent).GetLimitedWebPartManager(relativePageUrl,
            if (limitedWebPartManager != null)
                limitedWebPartManager.AddWebPart(new ApplyFontTagsWebPart(), "Top", 0);
        catch (Exception ex)
            string message = "Failed to add web part.";
                                                  new SPDiagnosticsCategory(typeof (ElBusHelper).FullName,
                                                  TraceSeverity.Unexpected, message, ex);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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