in

SharePoint University

Clean slate. Nothing but SharePoint.
Go, SharePoint!

Custom Content Type that uses a custom field

Last post 07-08-2008 7:48 AM by AlexMJ12. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 07-08-2008 6:16 AM

    • sigurbjorn
    • Top 500 Contributor
    • Joined on 06-19-2008
    • Reykjavik, Iceland

    Custom Content Type that uses a custom field

    Hello all...

    I have successfully created a custom field type and deployed that to my SharePoint site. Now I want to create a custom content type and use that custom field I created earlier in my content type.

    What is the preferred way of doing just that?

    I'm creating a solution using STSDEV 1.3 Simple Feature Solution. And everything is working great. I'm able to create the content type with base type field like Choice and Text but I would like to use my custom field as well.

    Best regards,
    Sigurbjorn

    http://sigurbjorn.wordpress.com
  • 07-08-2008 6:46 AM In reply to

    Re: Custom Content Type that uses a custom field

    SPContentType contentType=<your content type> ;

    SPField field= web.Fields["License"]; //use your fields storage and field name . License is my custom field deployed to site

    if (contentType.FieldLinks[field.Id] == null) //Check if field already exist

    {
        contentType.FieldLinks.Add(new SPFieldLink(field));
        contentType.Update();
     }

    Thanks,

    Alex 

  • 07-08-2008 7:09 AM In reply to

    • sigurbjorn
    • Top 500 Contributor
    • Joined on 06-19-2008
    • Reykjavik, Iceland

    Re: Custom Content Type that uses a custom field

    Thanks for that Alex, I will certainly consider your solution. But I'm trying to reference my custom field in the content type definition file.

    I'll post back if I will have a break through.

    Thanks,
    Sigurbjorn

    http://sigurbjorn.wordpress.com
  • 07-08-2008 7:39 AM In reply to

    • sigurbjorn
    • Top 500 Contributor
    • Joined on 06-19-2008
    • Reykjavik, Iceland

    Re: Custom Content Type that uses a custom field

    Ok I got it... It was just a silly bug or something. (I will not blaim STSDEV for this though!)

    So I define my Content Type using  the definition xml file as usually. Add a FieldRef and link that to the Field element and in the Type attribute I but the name of my custom field type.

    [FieldRef ID="{GUID}" Name="MyField" /]
    ...
    [Field Type="MyCustomField" ... /]

    The bug was that I used DebugDeploy or DebugReDeploy but somehow I needed to go in and manually deactivate the Feature and then re-activate it. Don't know if this is a bug or just some strange things in my setup.

    Thanks,
    Sigurbjorn

    http://sigurbjorn.wordpress.com
  • 07-08-2008 7:48 AM In reply to

    Re: Custom Content Type that uses a custom field

    Yes, I have same problem with STSDEV so now I completely delete feature and deploy again when using STSDEV.

    Thanks,

    Alex 

Page 1 of 1 (5 items)

Need SharePoint Training? Attend a SharePoint Bootcamp!
Forum content (c) original posters. Everything else (c) 2008 SharePoint Experts, Inc.