0

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?

1 Answer 1

0

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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