Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a feature in which I have a custom ListDefinition. Within the definition, I also have a ListInstance based off of the definition. When installing and activating the feature, these lists are provisioned in the site as expected.

When I retract my solution from the farm, these lists still exist, but throw said error that they cannot find the custom ListDefinition of which they are based on.

What is the best approach to handling this issue? I would like to do one of two things:

1) Delete the lists upon uninstallation (thought the feature receiver is not scoped to the individual site, but at the farm)

Edit - Clarification

The FeatureUninstalling event is run by the SharePoint timer job. It retracts the solution from the farm, wherever it may be installed. For that reason, properties.Feature is null. The event has access to SPFarm.Local, but there is nothing in that class to get what I need.

2) Somehow allow the lists to continue to function (read only?) when the feature is uninstalled.

share|improve this question
    
Could you please elaborate on the first alternative? Why you say that the feature receiver is not scoped to the web site/site collection? As far as I know, list template features should only be applicable to the site collection and web site scope. –  SPArchaeologist Oct 13 '11 at 15:18
    
see my update.. –  Tim Gabrhel Oct 13 '11 at 15:21
    
Ok, now I got what you meant. Maybe I haven't fully understand the extend of your issue, but isn't an option for you to implement a deactivation logic in the feature uninstall event of your receiver so that when a feature is uninstalled first it will be deactivated (something like this)? Then in the feature deactivating event you should be able to access the site/web object and process them as needed. –  SPArchaeologist Oct 13 '11 at 15:46
    
What scenario requires you to keep lists available that have no definition? This is counter-active to the framework of the SharePoint platform. It's how it works. –  James Love Oct 13 '11 at 15:52
    
I have a project that I developed that has a custom content type, list definition, list instance, and a workflow. Upon activation, everything is provisioned (caml based), then a feature receiver handles associating the workflow, creating views, etc. Upon deactivation, I would like to have the workflow removed, but the lists remain in the site (which works). Then, if the solution is uninstalled from the site, I want to clean up anything it created. The main list and it's custom task list are the only things left remaining. It wouldn't be too big of an issue if you could still navigate to them –  Tim Gabrhel Oct 13 '11 at 16:19

1 Answer 1

up vote 1 down vote accepted

I think you're gonna have to find all lists that use your template using a SPSiteDataQuery. This is scoped to an SPSite, so you're gonna have to run this against every site collection in your web application(s).

You'll have to iterate the web applications in the farm before you iterate the sites. Not sure how much is changed since 2007 (there has been changes, but off hand, can't remember which objects exactly, it's to do with the Service architecture though), but this blog shows how to iterate Web Applications: http://weblogs.asp.net/jevgeni/archive/2009/12/27/iterating-through-all-web-applications-in-a-sharepoint-farm.aspx

The SPSiteDataQuery will run, make sure you filter by ServerTemplate, setting the ID to your Base List Type. It's fairly quick and will return a DataTable. I think you can pull out from the datatable unique List GUIDs, then target those for deletion from the site collection.

This is tedious and resource intensive, yes. But it runs as a timer job operation, and should be running out of hours in a production environment, so impact to performance should be at a minimum (the web app would probably recycle anyway).

share|improve this answer
    
Upvote for the good answer. This sounds like a horrid approach because what if the solution is installed AND activated in more than 1 site? I'll need to get the solution, try to see its status, and continue from there. –  Tim Gabrhel Oct 13 '11 at 17:24
1  
I think I might have to roll up my list deletion into the FeatureDeactivated event. –  Tim Gabrhel Oct 13 '11 at 17:27
1  
Yeah, if it's activated in more than one site, you'll have to iterate over the sites in the webapplication object. If you have more than one web application that runs the solution, you'll have to iterate over the web applications in the farm, and then the sites within each web application. Sorry if that wasn't clear, but yeah. Ugly situation. All because Features don't deactivate upon uninstalling. –  James Love Oct 13 '11 at 17:27
    
I now have made my feature hidden, so it requires an administrator to manually run a script to deactivate/uninstall the feature (no accidental clicking) –  Tim Gabrhel Oct 13 '11 at 18:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.