I have a webpart i build using WSpBuilder and it works OK. When i use Deploy from Visual Studio it installs the WSP sharepoint and add the webpart to the webpart gallery. But it seems the feature does activate the webpart but i also want to remove it when deactivating it.(So i know i need to add something to the FeatureDeactivating
So i created a Feature With Reciever template and added it to the project.Which created a folder FeatureWithReceiver with the element and feature xml files and also a FeatureCode folder with FeatureWithReceiver.cs
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
SPSite site = null;
try
{
site = properties.Feature.Parent as SPSite;
using (SPWeb web = site.RootWeb)
{
SPList list = web.Lists["Web Part Gallery"];
// go through the items in reverse
//for (int i = list.ItemCount ā 1; i >= 0; iā)
for(int i=list.ItemCount-1; i >=0; i--)
{
// format name to look like a feature name
string webpartName = list.Items[i].Name;
webpartName = webpartName.Substring(0, webpartName.IndexOf("."));
// delete web parts that have been added
if (webpartName == "myStoreComms")
{
list.Items[i].Delete();
break;
}
}
}
}
finally
{
if (site != null)
site.Dispose();
}
}
In the feature.xml i have this below
<?xml version="1.0" encoding="utf-8"?>
<Feature Id="5d910db3-5adf-4f8e-a102-05d5a1653c59"
Title="FeatureWithReceiver"
Description="Description for FeatureWithReceiver"
Version="12.0.0.0"
Hidden="FALSE"
Scope="Web"
DefaultResourceFile="core"
ReceiverAssembly="MWO.SharePoint, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c9faae97dc801bd2"
ReceiverClass="MWO.SharePoint.FeatureWithReceiver"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="elements.xml"/>
</ElementManifests>
</Feature>
Element.xml
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="WebPartPopulation" Url="_catalogs/wp" RootWebOnly="TRUE">
<File Url="myStoreComms.webpart" Type="Ghostable">
<Property Name="Group" Value="MyGroup"></Property>
<Property Name="QuickAddGroups" Value="MyGroup" />
</File>
</Module>
</Elements>
But when i go to the site features i can see the feature but when i activate it it does puts the webpart in the gallery but when i deactivate it it doesn't remove it but i get error:
Failed to instantiate file "myStoreComms.webpart" from module "WebPartPopulation": Source path "myStoreComms.webpart" not found.
Any ideas.. .what could be wrong and thanks in advance