0

I'm looking into Sharepoint 2010 Feature upgrade framework and all over the net I'm seeing examples of how to upgrade a feature by adding a new field to a existing content type and this is done like this:

  <UpgradeActions>

<VersionRange BeginVersion="0.0.0.0" EndVersion="0.9.9.9">

  <ApplyElementManifests>

    <ElementManifest Location="SomeFunctionality_Iteration2\Elements.xml" />

  </ApplyElementManifests>



  <AddContentTypeField ContentTypeId="0x010073f25e2ac37846bb8e884770fb7307c7"

      FieldId="{536DC46C-DC26-4DB0-A97C-7C21E4362A85}" PushDown="TRUE"/>

  <AddContentTypeField ContentTypeId="0x010073f25e2ac37846bb8e884770fb7307c7"

      FieldId="{4E7A6719-011A-47EA-B983-A4941D688CA6}" PushDown="TRUE"/>

What i don't understand is how would i perform an upgrade to a feature which would rename,*delete* or change any other property a field declaratively from the content type the feature already deployed.

All over the net I'm seeing examples of how to add a Field, but how do i change properties of existing ones using Feature Versioning and Upgrading.

Thanks!

Narcis
  • 5,862
  • 3
  • 23
  • 30

1 Answers1

0

You have to do that using code in the Feature receiver (in Feature_Updating). There's no way to delete or rename a Field using CAML.

Rob Windsor
  • 6,744
  • 1
  • 21
  • 26
  • But if i directly change the Element File which contains (the list definition) the content type definition and I update the Field properties (like Title ) the changes seem to show in list settings when i hit F5 in VS 2010. How is that possible? – Narcis Jul 31 '12 at 17:13
  • I'm not certain about list definitions but I can speak to site columns and content types. If you deactivate a Feature that created site columns or content types via CAML, the site columns or content types that are not is use will be removed. Those that are in use won't be removed - in fact, they can't be removed. – Rob Windsor Jul 31 '12 at 18:28
  • Continuing my last comment... So, as a developer you can change the definitions of site columns or content types and just redeploy to effect those changes as long as the site columns or content types are not in use. Once they are, you need to use the Feature upgrade technique to make changes – Rob Windsor Jul 31 '12 at 18:30
  • Hmm i'm pretty sure i added some list items which remained after the upgrade. Anyway the problem i have with upgrading from code is that i have to also keep in sync the sharepoint solution for when a new site is created that uses my custom solution and or another developer joins the team and needs to install ths solution. – Narcis Jul 31 '12 at 19:16
  • Your solution needs to handle both cases. The case where it has been installed previously but one or more Features are being upgraded, and the case where you are installing the solution for the first time. Check out this screencast, it covers the process in detail http://bit.ly/ld7dGY – Rob Windsor Jul 31 '12 at 19:39
  • Thats what i was afraid of. Thank you Rob Windsor. But from your experience when the client wants a lot of changes, how do you keep track of all the upgrade code and the order in which the code must be installed. Also when do you throw out this code so you won't polute your VS solution – Narcis Jul 31 '12 at 20:21
  • I generally do everything I can in code. I put the code to get to version 1 of a feature in the Feature_Activated of the receiver. Then for every version upgrade I create a class to perform the upgrade (each class has a static method called Upgrade). Then I call this method both at the end of Feature_Activated and inside Feature_Upgrading. – Rob Windsor Jul 31 '12 at 21:49