Marc
Marc

Reputation: 6771

How to create a webpart page with included webpart in sandboxed solution

I know its possible to create a wiki page in a sandbox solution with this:

SPUtility.CreateNewWikiPage(list, "{mysiteurl}/CodeGeneratedPage.aspx");

But how can I (if possible) create a webpart page with included webpart in my document library? Because all I can find (like this) is only working in farm solutions. Is there a workaround somehow?

Notice: I post this question here because there are way more people here as on the Sharepoint site.

Upvotes: 3

Views: 3601

Answers (1)

Dennis G
Dennis G

Reputation: 21788

Good find. You cannot use the SPLimitedWebPartManager in sandboxed code and hence can't use it to put WebParts on pages.

The only way to provision WebParts to pages is the declarative way (i.e. XML), so you will have to do something like this in an elements.xml file:

  <AllUsersWebPart WebPartZoneID="MainWebPartZone" WebPartOrder="1">
    <![CDATA[
      <webParts>
        <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
          <metaData>
            <type name="MyComp.WebParts.SampleWebPart, MyComp.WebParts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5" />
            <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
          </metaData>
          <data>
            <properties>
              <property name="Title" type="string">Sample WebPart</property>
            </properties>
          </data>
        </webPart>
      </webParts>
    ]]>       
  </AllUsersWebPart>

These links will help you along your way:


and some more:

Upvotes: 2

Related Questions