1

Let's say I have following elements in my solution:

Site Column:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">  
  <Field
       ID="{11111111-1111-1111-1111-111111111111}"
       Name="CustomAddress"
       Type="Text" 
       DisplayName="Address" 
       Required="TRUE">
  </Field>
</Elements>

Site Content Type:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <!-- Parent ContentType: Item (0x01) -->
  <ContentType ID="0x010011111111111111111111111111111111"
               Name="CustomContentType"
               Description="My Custom Content Type"
               Inherits="TRUE"
               Version="0">
    <FieldRefs>
      <FieldRef ID="{11111111-1111-1111-1111-111111111111}" Name="CustomAddress" />
    </FieldRefs>
  </ContentType>
</Elements>

Custom List Schema:

<List xmlns:ows="Microsoft SharePoint" Title="Contracts" EnableContentTypes="TRUE" FolderCreation="FALSE" Direction="$Resources:Direction;" Url="Lists/Auftraege" BaseType="0" xmlns="http://schemas.microsoft.com/sharepoint/">
  <MetaData>
    <ContentTypes>
      <ContentTypeRef ID="0x010011111111111111111111111111111111" />
    </ContentTypes>
    <Fields>
    </Fields>
    <Views>
       ...

This works, I have deployed my elements exactly this way. I have not defined the site column in the Elements.xml file of either my list template nor my list instance. So, why does this work when the accepted answer on this question says that in order to use custom site columns in custom list schema, I need to explicitly define the same field in said schema? Am I missing something here? How does the deployment of fields, content types and lists work in regards to Elements.xml and Schema.xml files?

EDIT: I should probably state that when I provision my elements like this, SharePoint expectedly appends GUIDs to my custom content type when I use it in my custom list So the content type id becomes 0x0100111111111111111111111111111111110022222222222222222222222222222222. Dunno about the fields though, haven't tested it yet with them.

2

I think the accepted answer you're pointing is not completely accurate.
The question raised in that post is more probably "Why do all examples I see insert the fields twice?" instead of "Why do I need to insert the fields twice?". I think this is at least how the answerer understood it.

The point is: you can insert them twice (i.e. redefine the fields at the list level in addition to the content type level). This has the advantage to allow you to override some properties of the fields (like the display name) if you want to (the modifications would take place only at the list level).
But this does not mean you must...

  • thanks for your answer. one question though, why do some examples define site columns in the list template's Elements.xml, additionally to the Schema.xml of the list and Elements.xml of site column/content type? Or is this just another "level" in the overriding-hierarchy of SharePoint? – LeonidasFett Feb 18 '17 at 15:50
  • Do you have a pointer to such examples? You can define a site column (same internal name/ID) only once AFAIK, i.e. in one file (that could contain other artefacts), but not in two different files. – Evariste Feb 18 '17 at 17:20
  • Sadly, no. I would have to search for myself too. So you mean I can define site columns in both Elements.xml and Schema.xml of the list instance, but not two Elements.xml files at once? That also makes things a little more clearer about the difference between Schema.xml and Elements.xml. – LeonidasFett Feb 18 '17 at 17:26
  • Site columns must be defined only once in your entire XML files. – Evariste Feb 18 '17 at 17:56
  • ok thanks for all the help. you made things a little more clearer. :) – LeonidasFett Feb 18 '17 at 20:08

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.