locked
Set Custom Properties for a custom field type within a content type feature RRS feed

  • Question

  • Hi,

    I have created a custom field type (derived from SPFieldText) and added a custom property "MyProperty". Now what I am looking for is, I need to use this field type in my Content Type feature.

    How can I specity my custom property within a Content Type definition file, just like what we do with OOB field types?

    I've seen a workaround here  but it only solves only the problem of XSD validation. Site column is getting installed properly but the value that I specify in the feature as a property is not set for the column after installing the feature.

    Thank in advance

    Arun


    Arun D Gangadharan
    Wednesday, October 27, 2010 4:38 PM

All replies

  • Arun,

    I have created a custom field with a custom property in one of the solutions I'm working on and used the <Customization> element to get store it with the field

     

    <Field ID="$$" Name="$$" Type="$$" DisplayName="$$" Group="$$" AllowDeletion="FALSE">
     <Customization>
     <ArrayOfProperty>
      <Property>
      <Name>DelimitedPropertyValues</Name>
      <Value></Value>
      </Property>
     </ArrayOfProperty>
     </Customization>
     <Default>(none)</Default>
    </Field>
    
    And then to get those values in my custom field definitions, I added the following code

     

     

    Field.GetCustomProperty("DelimitedPropertyValues")
    

     

    Same for SetCustomProperty.

    Let me know if that works for you.

    • Edited by Mike Walsh FIN Saturday, November 6, 2010 4:37 AM sig removed - do not ask people to mark your posts as answers
    Friday, November 5, 2010 9:10 PM
  • Hi Dennis,

    Thanks for the reply.

    I tried the approach that you mentioned. But I am getting an error at the line "<customization>".

    The element 'Field' in namespace 'http://schemas.microsoft.com/sharepoint/'
    has invalid child element 'Customization' in namespace 'http://schemas.microsoft.com/sharepoint/'. List of possible ele
    ments expected: 'DefaultFormula, Default, DisplayPattern, FieldRefs, Formula, CHOICES, MAPPINGS, DisplayBidiPattern' in
    namespace 'http://schemas.microsoft.com/sharepoint/'.

    How do I solve this?

    Thanks in advance.

    Arun


    Arun D Gangadharan
    Monday, November 8, 2010 9:13 AM
  • Arun,

    You will need to modify your wss.xsd file in 12 hive to include the following:

    under <xs:complexType name="FieldDefinition" mixed="true"> -> <xs:all>, add the following

    <xs:element name="Customization" type="CustomizationDefinition" minOccurs="0" maxOccurs="1"/>
    
    also, add a complex type for the definition just defined inside <xs:schema> element.

    <xs:complexType name="CustomizationDefinition">
      <xs:sequence>
       <xs:element name="ArrayOfProperty">
        <xs:complexType>
         <xs:sequence>
          <xs:element name="Property">
           <xs:complexType>
            <xs:sequence>
             <xs:element name="Name" type="xs:string"/>
             <xs:element name="Value" type="xs:string"/>
            </xs:sequence>
           </xs:complexType>
          </xs:element>
         </xs:sequence>
        </xs:complexType>
       </xs:element>
      </xs:sequence>
     </xs:complexType>
    

    recycle App Pools and try to deploy your solution again, you should not get an error this time.

     


    Dennis Alzoubi
    Monday, November 8, 2010 3:46 PM
  • Hi Dennis,

    I have tried your approach. When I access GetCustomProperty("DelimitedPropertyValues"), I am getting it as NULL. I put this code in the constructor of my field class.

    Any idea what is going wrong?

    Thank you


    Arun D Gangadharan
    Tuesday, November 9, 2010 9:04 AM
  • Also, I don't think I can go ahead with this approach since it involves editing wss.xsd. There should be some way around using APIs. Let me check out.

     


    Arun D Gangadharan
    Wednesday, November 10, 2010 6:55 AM
  • What I did here is create a property that gets the value of the Customization attribute

    private CrossSiteLookupProperty _LookupProperty;
    /// <summary>
    /// Gets the lookup property.
    /// </summary>
    /// <value>The lookup property.</value>
    public CrossSiteLookupProperty LookupProperty
    {
      get
      {
        return _LookupProperty ??
            (_LookupProperty =
            new CrossSiteLookupProperty(
              Field.GetCustomProperty("DelimitedPropertyValues")));
      }
    }
    

    I know its not a best practice to change the WSS.xsd as it gets overwritten with updates and service packs, but the good news is that you only need it when you deploy the solution file as it gets validated against the wss.xsd. but after that, you don't really care.

    But let me know if you find anything else that works.


    Dennis Alzoubi
    Wednesday, November 10, 2010 3:11 PM
  • Thank you Dennis.

    In fact I have found a workaround.

    Instead of using a "elements.xml" I included a plain xml file within the feature. I added field CAML into this file and with a feature receiver code I picked each line of caml from the text file and executed with SPFieldCollection.AddFieldAsXml(). This medthod actually doesnt validate the CAML against the WSS.XSD. So my fields created perfectly with the properties I specified within the CAML.

    Thank you


    Arun D Gangadharan
    Thursday, November 11, 2010 4:09 AM