I have a feature which on activation has to create a list called Scanners. Only one column from the list (Title) is actually used in my app. The list needs to be pre-populated with some values. To fill in the values I used the ListInstance's Elements.xml, so now it looks like this:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <ListInstance Title="Scanners"                
          <Field Name="Title">DevScanner</Field>
          <Field Name="Title">ProdScanner</Field>
          <Field Name="Title">TestScanner</Field>

The list instance is created at the Site(Web) level. On Feature activation, the list instance should be created only if the site doesn't already contain a list with the same name (Scanners). The current behavior does this, but with one problem. On each activation, the data gets added again to the existing list, so I end up with lots of duplicate rows. How can this be prevented?

The client's specs don't allow me to delete the list on feature deactivation. I tried fiddling with the Deployment Conflict Resolution setting, with no success.


If your feature can be activated/deactivated multiple times then you should not use the <data> elemente to populate elements into the list instance. As you get the duplicate item effect that you're experiencing and there is no way to prevent that.
The Deployment Conflict Resolution setting is only used by Visual Studio when deploying to your local environment (and the way it solves the problem is by deleting the list instance). I'm not 100% agreeing with MS that this is good idea as it hides a lot of problems which will occur in test/production from the dev. environment.

The solution for your problem is to pre-populated rows into the list instance without duplication. You should pre-populate using code in a FeatureReceiver where you can check if the list is empty before adding the rows.


You can also add the following line for each <row>:

<Field Name="ID">1</Field>

For example:

      <Field Name="Title">DevScanner</Field>
      <Field Name="ID">1</Field>

As the ID is still the same it won't add a new record, so it prevents duplicate rows.


This could solve the duplicates: http://jeremysublett.com/archive/2008/12/28/re-provisioning-data-in-a-sharepoint-list.aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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