I have two list that I need to delete when a solution is deactivated and removed. But my code doesn't seems to be working. I am trying to delete and remove the quicklinks to the lists in FeatureDeactivating event receiver:
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
using (SPWeb webSite = properties.Feature.Parent as SPWeb)
{
if (webSite != null)
{
SPList customerList = webSite.Lists.TryGetList("SandBoxProjet - Customers");
if (customerList != null)
{
customerList.OnQuickLaunch = false;
SPListItemCollection lic = customerList.Items;
foreach (SPListItem item in lic)
{
item.Delete();
}
customerList.Update();
customerList.Delete();
}
SPList leadList = webSite.Lists.TryGetList("Sales Lead");
if (leadList != null)
{
leadList.OnQuickLaunch = false;
SPListItemCollection lic = leadList.Items;
foreach (SPListItem item in lic)
{
item.Delete();
}
leadList.Update();
leadList.Delete();
}
webSite.Update();
}
}
}
What am I doing wrong? I am deploying the solution as sandbox. The list seems to live even after the solution is deactivated and I am able to make modifications to the data.
SPWeb webSite = properties.Feature.Parent as SPWeb;instead ofSPWeb mySite= SPContext.Current.Web;! Why? Any reason? – Abdel Raoof Olakara Jun 17 '12 at 18:47