Click here to Skip to main content
15,902,860 members
Articles / Operating Systems / Windows
Technical Blog

Custom fields and save site as template problem

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
12 Apr 2013CPOL 5.3K  
A solution for the custom fields and save site as template problem.

If you have custom fields with custom properties on your site and use default field serialization you'll get an error while saving such site as template. It happens because of template validation through XSD-scheme 14\TEMPLATE\XML\wss.xsd. Let's see how it looks:

XML
<xs:complexType name="FieldDefinition" mixed="true">
    <xs:all>
      <xs:element name="FieldRefs" type="FieldRefDefinitions" minOccurs="0" maxOccurs="1" />
      <xs:element name="DisplayPattern" type="CamlViewRoot" minOccurs="0" maxOccurs="1" />
      <xs:element name="DisplayBidiPattern" type="CamlViewRoot" minOccurs="0" maxOccurs="1" />
      <xs:element name="CHOICES" type="CHOICEDEFINITIONS" minOccurs="0" maxOccurs="1" />
      <xs:element name="MAPPINGS" type="MAPPINGDEFINITIONS" minOccurs="0" maxOccurs="1" />
      <xs:element name="Default" type="xs:string" minOccurs="0" maxOccurs="1" />
      <xs:element name="Formula" type="xs:string" minOccurs="0" maxOccurs="1" />
      <xs:element name="FormulaDisplayNames" type="xs:string" minOccurs="0" maxOccurs="1" />
      <xs:element name="DefaultFormula" type="xs:string" minOccurs="0" maxOccurs="1" />
      <xs:element name="Validation" type="ValidationDefinition" minOccurs="0" maxOccurs="1" />
      <xs:element name="Customization" type="CustomizationDefinition" minOccurs="0" maxOccurs="1" />
    </xs:all>
    <xs:attribute name="Aggregation" type="xs:string" />
    <xs:attribute name="AllowDeletion" type="TRUEFALSE" />
    <xs:attribute name="AllowDuplicateValues" type="TRUEFALSE" />
    <xs:attribute name="AllowHyperlink" type="TRUEFALSE" />
    <xs:attribute name="AllowMultiVote" type="TRUEFALSE" />
    <xs:attribute name="AppendOnly" type="TRUEFALSE" />
    <xs:attribute name="AuthoringInfo" type="xs:string" />
    <xs:attribute name="BaseType" type="xs:string" />
    <xs:attribute name="CalType" type="xs:int" />
    <xs:attribute name="CanToggleHidden" type="TRUEFALSE" />
    <xs:attribute name="ClassInfo" type="xs:string" />
    <xs:attribute name="ColName" type="xs:string" /> 
    <xs:attribute name="ColName2" type="xs:string" use="optional" />
    <xs:attribute name="Commas" type="TRUEFALSE" />
    <xs:attribute name="Customization" type="xs:string" />
    <xs:attribute name="DefaultListField" type="TRUEFALSE" />
    <xs:attribute name="Decimals" type="xs:int" />
    <xs:attribute name="Description" type="xs:string" />
    <xs:attribute name="Dir" type="xs:string" />
    <xs:attribute name="Direction" type="xs:string" />
    <xs:attribute name="DisplayImage" type="xs:string" />
    <xs:attribute name="DisplayName" type="xs:string" />
    <xs:attribute name="DisplayNameSrcField" type="xs:string" />
    <xs:attribute name="DisplaySize" type="xs:int" />
    <xs:attribute name="Div" type="xs:string" />
    <xs:attribute name="ListItemMenu" type="TRUEFALSE" />
    <xs:attribute name="ListItemMenuAllowed" type="ListItemMenuType" />
    <xs:attribute name="EnableLookup" type="TRUEFALSE" />
    <xs:attribute name="EnforceUniqueValues" type="TRUEFALSE" />
    <xs:attribute name="ExceptionImage" type="xs:string" />
    <xs:attribute name="FieldRef" type="xs:string" />
    <xs:attribute name="FillInChoice" type="TRUEFALSE" />
    <xs:attribute name="Filterable" type="TRUEFALSE" />
    <xs:attribute name="FilterableNoRecurrence" type="TRUEFALSE" />
    <xs:attribute name="ForcedDisplay" type="xs:string" />
    <xs:attribute name="ForcePromoteDemote" type="TRUEFALSE" />
    <xs:attribute name="Format" type="DisplayFormat" />
    <xs:attribute name="FromBaseType" type="TRUEFALSE" />
    <xs:attribute name="HeaderImage" type="xs:string" />
    <xs:attribute name="Height" type="xs:int" />
    <xs:attribute name="Hidden" type="TRUEFALSE" />
    <xs:attribute name="HTMLEncode" type="xs:string" />
    <xs:attribute name="Id" type="xs:string" />
    <xs:attribute name="IMEMode" type="IMEMode" />
    <xs:attribute name="Indexed" type="TRUEFALSE" />
    <xs:attribute name="IsolateStyles" type="TRUEFALSE" />
    <xs:attribute name="IsRelationship" type="TRUEFALSE" />
    <xs:attribute name="JoinColName" type="xs:string" />
    <xs:attribute name="JoinType" type="JoinType" />
    <xs:attribute name="LCID" type="LocalizableString" />
    <xs:attribute name="LinkToItem" type="TRUEFALSE" />
    <xs:attribute name="LinkToItemAllowed" type="ListItemMenuType" />
    <xs:attribute name="List" type="xs:string" />
    <xs:attribute name="Max" type="xs:float" />
    <xs:attribute name="Min" type="xs:string" />
    <xs:attribute name="Mult" type="TRUEFALSE" />
    <xs:attribute name="Name" type="xs:string" use="required"/>
    <xs:attribute name="NegativeFormat" type="xs:string" />
    <xs:attribute name="Node" type="xs:string" />
    <xs:attribute name="NoEditFormBreak" type="TRUEFALSE" />
    <xs:attribute name="NumLines" type="xs:int" />
    <xs:attribute name="Percentage" type="TRUEFALSE" />
    <xs:attribute name="PIAttribute" type="xs:string" />
    <xs:attribute name="PITarget" type="xs:string" />
    <xs:attribute name="PrimaryPIAttribute" type="xs:string" />
    <xs:attribute name="PrimaryPITarget" type="xs:string" />
    <xs:attribute name="Presence" type="TRUEFALSE" />
    <xs:attribute name="PrimaryKey" type="TRUEFALSE" />
    <xs:attribute name="ReadOnly" type="TRUEFALSE" />
    <xs:attribute name="ReadOnlyEnforced" type="TRUEFALSE" />
    <xs:attribute name="RelationshipDeleteBehavior" type="DeleteBehaviorType" />
    <xs:attribute name="RenderXMLUsingPattern" type="TRUEFALSE" />
    <xs:attribute name="Required" type="TRUEFALSE" />
    <xs:attribute name="RestrictedMode" type="TRUEFALSE" />
    <xs:attribute name="ResultType" type="xs:string" />
    <xs:attribute name="RichTextMode" type="xs:string" />
    <xs:attribute name="RichText" type="TRUEFALSE" />
    <xs:attribute name="Sealed" type="TRUEFALSE" />
    <xs:attribute name="SeperateLine" type="TRUEFALSE" />
    <xs:attribute name="SetAs" type="xs:string" />
    <xs:attribute name="ShowAddressBookButton" type="TRUEFALSE" />
    <xs:attribute name="ShowAlways" type="TRUEFALSE" />
    <xs:attribute name="ShowField" type="xs:string" />
    <xs:attribute name="ShowInDisplayForm" type="TRUEFALSE" />
    <xs:attribute name="ShowInEditForm" type="TRUEFALSE" />
    <xs:attribute name="ShowInFileDlg" type="TRUEFALSE" />
    <xs:attribute name="ShowInListSettings" type="TRUEFALSE" />
    <xs:attribute name="ShowInNewForm" type="TRUEFALSE" />
    <xs:attribute name="ShowInViewForms" type="TRUEFALSE" />
    <xs:attribute name="Sortable" type="TRUEFALSE" />
    <xs:attribute name="StorageTZ" type="xs:string" />
    <xs:attribute name="StripWS" type="xs:string" />
    <xs:attribute name="SuppressNameDisplay" type="TRUEFALSE" />
    <xs:attribute name="TextOnly" type="TRUEFALSE" />
    <xs:attribute name="Title" type="xs:string" />
    <xs:attribute name="Type" type="xs:string" use="required" />
    <xs:attribute name="UniqueId" type="xs:string" />
    <xs:attribute name="UnlimitedLengthInDocumentLibrary" type="TRUEFALSE" />
    <xs:attribute name="URLEncode" type="TRUEFALSE" />
    <xs:attribute name="URLEncodeAsURL" type="TRUEFALSE" />
    <xs:attribute name="Version" type="xs:string" use="optional" />
    <xs:attribute name="Viewable" type="TRUEFALSE" />
    <xs:attribute name="WikiLinking" type="TRUEFALSE" />
    <xs:attribute name="Width" type="xs:int" />
    <xs:attribute name="WebId" type="UniqueIdentifier" use="optional" />
    <xs:attribute name="XName" type="xs:string" />
    <xs:attribute name="ID" type="UniqueIdentifier" />
    <xs:attribute name="Group" type="xs:string" />
    <xs:attribute name="MaxLength" type="xs:int" />
    <xs:attribute name="SourceID" type="xs:string" />
    <xs:attribute name="StaticName" type="xs:string" />
    <xs:attribute name="JoinRowOrdinal" type="xs:int" />
    <xs:attribute name="RowOrdinal" type="xs:int" />
    <xs:attribute name="ShowInVersionHistory" type="TRUEFALSE" />
    <xs:attribute name="PrependId" type="TRUEFALSE" />
    <xs:attribute name="DisplaceOnUpgrade" type="TRUEFALSE" />
    <xs:attribute name="UserSelectionMode" type="xs:string" />
    <xs:attribute name="UserSelectionScope" type="xs:int" />
    <xs:anyAttribute namespace="##other" processContents="lax" />    
</xs:complexType>

If you use default namespace for your custom property and its name differs from properties defined in this file, you'll get validation error because of this attribute namespace="##other" of xs:anyAttribute element.

You can change schema to pass validation. Just remove an attribute namespace="##other" and you can create fields with any properties with default namespace.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead Plumsail
Russian Federation Russian Federation
Expert in SharePoint
The leader of SharePoint Forms Designer Team: http://spform.com
Co-founder of Plumsail: http://plumsail.com
My blog: http://formsdesigner.blogspot.com

Comments and Discussions

 
-- There are no messages in this forum --