Search code examples
sharepointmossschemaweb-parts

Feature element repeatedly added with every feature activation/deactivation


This is a very minor behavior when compared with the entire scope, but it is one that I'd like to put a stop to.

I have created a very, very simple SharePoint Feature. It has two elements in its manifest: an aspx webpart page, and an elements xml. I'll paraphrase my elements xml, which just adds a module, below.

 <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <Module Name="Pass" Url="" Path="">
      <File Url="pasq.aspx" NavBarHome="True" Type="Ghostable">
        <AllUsersWebPart WebPartZoneID="Left" WebPartOrder="0">
                  <![CDATA[
                   WARGH THIS PART DOESN'T MATTER FOR THIS QUESTION!
                  ]]>
        </AllUsersWebPart>
      </File>
    </Module>
</Elements>

Now, on the first time I deploy and activate this feature, it works properly. But if I have to deactivate and then reactivate the feature in order to fix some properties in the webpart, then I find myself with a second webpart on the page. Naturally, each similar cycle will just add more and more. I understand that a new webpart must be created in order to employ the changes I just made, but why is the old webpart still on the page? Can I make this older webpart go away automatically as part of the feature activation/deactivation process without needing to employ a Receiver class?

EDIT Based on the fact that I've already employed a Receiver to solve this issue, I ended up just adding the webpart removal as part of feature deactivation. But I was still hoping that maybe there's something I'm missing.


Solution

  • SharePoint doesn't offer a declarative way (xml) to remove feature elements automagically. You'll have to add some code in a FeatureDeactiving method on the feature receiver to remove it programatically, sorry.