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 site scoped Feature which specifies a list as such:

<?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
        <ListInstance Title="Test List"
            OnQuickLaunch="FALSE"
            TemplateType="101"
            FeatureId="<snip>"
            Url="Lists/TestList"
            Description="">
        </ListInstance>
    </Elements>

This feature may be activated in multiple site collections and the contents of the list may be modified independently in each site collection.

What I'm trying to do is to allow changes in each site collection to be persisted when the feature is deactivated then reactivated and the list removed altogether when the feature is uninstalled.

My initial attempt was to use a SPFeatureReceiver but I'm having trouble getting the exact behavior I'm seeking.

I can't remove the list when the feature is deactivated because it will lose any customizations if the feature is ever reactivated.

I attempted to remove the list in FeatureUninstalling but I'm not sure how to access all instances of the list in all site collections to remove it. Do I need to iterate over every site collection and remove the list if its present? If so, how can I list of all the site collections that exist?

share|improve this question

1 Answer 1

You can iterate all the site collections on your web application and use SPSiteDataQuery object to get all the lists instances by there content type. Here's an example:

<Where>
  <Eq>
    <FieldRef Name='ContentType'/>
    <Value Type='Text'>YourContentType</Value>
  </Eq>
</Where>
share|improve this answer

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.