How to set default value for a column of content type in Sharepoint

content-typesharepoint

i create a content type using feature as below

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Field ID ="{4C939423-2090-413d-B241-724D9B66F74B}"
         Name="VersionNumer"
         DisplayName="Version Number"
         Type="Text"
         Required="TRUE"
         Group="CT" >
    <Default>0</Default>
  </Field>


  <Field ID ="{33E51B7A-FEE2-4995-B4BB-9F3F909C1015}"
         Name="DocumentType"
         DisplayName="Document Type"
         Type="Choice"
         Required="TRUE"
         Group="CT">
    <Default>Other</Default>

    <CHOICES>
      <CHOICE>Document</CHOICE>
      <CHOICE>Excel</CHOICE>
      <CHOICE>PowerPoint</CHOICE>
      <CHOICE>Other</CHOICE>
    </CHOICES>
  </Field>

  <ContentType ID="0x0101000728167cd9c94899925ba69c4af6743e"
               Name="myCT"
               Group="myCT"
               Description="myCT"
               Version="0">
    <FieldRefs>
      <FieldRef ID="{4C939423-2090-413d-B241-724D9B66F74B}" Name="VersionNumber" DisplayName="Version Number" Required="TRUE" />
      <FieldRef ID="{33E51B7A-FEE2-4995-B4BB-9F3F909C1015}" Name="DocumentType" DisplayName="Document Type" Required="TRUE"  />      
    </FieldRefs>  
  </ContentType>
</Elements>

How can i set default value for VersionNumer is 0 and default value for DocumentType is Other? I used default tag but it was not efficent.

And another question, how to force user to input VersionNumer and DocumentType. I used atrtibute required="true" but it was not successful.
Thanks in advance.

Best Answer

I've tried this in my environment, it works perfectly. I copy 'n' pasted the contents of elements.xml and didn't make a single modification.

Try this:

  • Delete your existing site columns and content type (in that order)
  • Deactivate your feature
  • IISRESET
  • Activate your feature again and check if the default values are ok, they should be