3

I've developed a custom web part. I would like to create a feature that when activated via STSADM adds the web part to the default page of a WSS Site. Hopefully this can be done without writing code.

This webpart is meant to de deployed to the web application's bin directory and featurereceiver must be installed to the GAC. The AllUsersWebPart element looks promising, but I can't figure out how to get it to work.

TIA,

jt

Jason
  • 15,915
  • 3
  • 48
  • 72

1 Answers1

4

The AllUsersWebPart tag allow us to insert one webpart and place it where we want using WebPartOrder and WebPartZone attributes. The content of the tag is the dwp (or webpart) of your webpart. For example, for a dwp:

<AllUsersWebPart WebPartZoneID="MiddleLeftZone" WebPartOrder="0">
    <![CDATA[                                              
      <WebPart xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/WebPart/v2">
        <FrameType>None</FrameType>
        <AllowMinimize>true</AllowMinimize>
        <IsVisible>true</IsVisible>
        <Assembly>Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
        <TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>
        <ContentLink xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
        <Content xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor">
          <Value>&lt;iframe src="$Resources:Summary_Url;" frameborder="0" scrolling="no" width="100%" height="100%"&gt;&lt;/iframe&gt;</Value>
        </Content>
        <PartStorage xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
    </WebPart>
    ]]>
  </AllUsersWebPart>

For a webpart:

<AllUsersWebPart WebPartZoneID="MiddleLeftZone" WebPartOrder="1">
    <![CDATA[                                              
      <webParts>
        <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
          <metaData>
            <type name="MyClass, MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f3b9d1137704f880" />
            <importErrorMessage>No se puede importar este elemento Web.</importErrorMessage>
          </metaData>
          <data>
            <properties>
              <property name="AllowClose" type="bool">False</property>
              <property name="AllowMinimize" type="bool">False</property>
              <property name="AllowConnect" type="bool">True</property>
              <property name="ChromeType" type="chrometype">None</property>
              <property name="Hidden" type="bool">False</property>
              <property name="AllowEdit" type="bool">False</property>
              <property name="AllowZoneChange" type="bool">False</property>
              <property name="MissingAssembly" type="string">No se puede importar este elemento Web.</property>
              <property name="ChromeState" type="chromestate">Normal</property>
            </properties>
          </data>
        </webPart>
      </webParts>
    ]]>
  </AllUsersWebPart>

I haven't tried before but I think it can be done once the web has been created. Try it and tell us.

jaloplo
  • 941
  • 2
  • 12
  • 32
  • These two examples have been taken from a Feature I made to a customer. The first one adds a content webpart that have an iframe with a source url readed from the resource file of the feature. The second one is webpart of my own, the only thing you would have to change is the assembly declaration. – jaloplo Mar 14 '09 at 18:00
  • @jaloplo Thank you a bunch! I was having difficulty getting a custom web part of my own working, and never knew that .dwp and .webpart were handled differently in the schema. Thanks to finding your post, I was able to fix this issue! – Grace Note Apr 13 '10 at 14:20