Answered Help understand ContentType/List upgrade

  • martedì 21 agosto 2012 16:28
     
     

    Everywhere I read on the web, it says that Content Types and List once deployed through Xml files (Caml/Declarative way) they cannot be updated anymore.

    I have created a VS 2010 solution, created a SharePoint List Definition with a Content type inline and deployed it. Everything works. Then added some items to my new list.

    Now I edit the Schema.xml of the ListDefinition, I add a couple of fields, remove some, and change Type of others (from DateTime to Number). Hit Deploy. Deploy succeeds.

    When i check the site, my content type fields have updated correctly and my list items previously entered are still there. So what's that about?

    I saw that VS does a Retract/Add Solution/Activate, but if no data is lost and the content types update correctly, why use bother writing Feature receivers and upgrade code when i can simply "Retract/Add Solution/Activate"

    Thanks


    Me http://www.zapacila.com

Tutte le risposte

  • martedì 21 agosto 2012 16:35
    Postatore
     
     Con risposta

    It's not that you CANNOT do it, it's more that it's NOT SUPPORTED if you did do it.

    Picture it this way.  If you have the following list definition:

      Title
      Field1
      Field2

    If you now add data thus:

      Title1  Field1Row1  Field2Row1
      Title2  Field1Row2  Field2Row2

    If you then add a new field to the list definition and remove an old field to have the definition end thus:

      Title
      Field2
      Field3

    The data would show thus:

      Title1  Field2Row1  <blank>
      Title2  Field2Row2  <blank>

    The problem is that the change in definition has now orphaned the values "Field1Row1" and "Field1Row2" in the database.  Continually do this and more and more orphaned data accumulate.  In addition, consider what happens if you were to change a data type e.g. change a date field to a number field instead.  SharePoint may not be able to render the content and throw an error instead.

    This is why changing definitions are NOT supported by Microsoft.

    Just because you CAN do it, doesn't mean you should.


    I trust that answers your question...

    Thanks
    C

    http://www.cjvandyk.com/blog | LinkedIn | Facebook | Twitter | Quix Utilities for SharePoint | SharePoint Admin Nav Console (SPANC)

    • Contrassegnato come risposta zapacila89 martedì 21 agosto 2012 20:58
    •  
  • martedì 21 agosto 2012 21:05
     
     

    Thanks!!

    My problem is that the Customer always makes small changes to the fields (rename Display name, change required or not .. etc), i would like to avoid writing code to do this when i can easily update the CAML.

    They are also always adding more fields, it's a lot easier to add them directly in CAML (and have them ready for New Sites too) than writing in code and than maintaining versions of the code (i know in SP2010 there is feature upgrade for adding fields which sound more likely)

    So basically doing the retract/deactivate/add/activate i should be careful only when removing fields (delete the orphans)


    Me http://www.zapacila.com

  • martedì 21 agosto 2012 21:11
     
     
    Also if i I'm deactivating a Feature which deployed a Field/Content type how come when i reactivate it the list items still work ?

    Me http://www.zapacila.com