Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Chris Houston 533 posts 977 karma points MVP admin c-trib
    Jul 08, 2009 @ 11:33
    Chris Houston
    0

    Creating Umbraco DocType's using the API

    Hi All,

    I would like to create new doctype's ( and child doc type's ) using the API and I was hoping someone can point me in the right direction as I've Googled and searched the Forum but with no success.

    Any pointers would be much appreciated!

    Cheers,

    Chris

  • Jan Skovgaard 11258 posts 23500 karma points MVP 7x admin c-trib
    Jul 08, 2009 @ 11:37
    Jan Skovgaard
    1

    Here is the API reference: http://umbraco.org/apiDocs/index.html

    /Jan

  • Jan Skovgaard 11258 posts 23500 karma points MVP 7x admin c-trib
    Jul 08, 2009 @ 11:39
    Jan Skovgaard
    2

    Whoops - forgot to also mention the API cheatsheet from the wiki on our, which you'll find here: http://our.umbraco.org/wiki/reference/api-cheatsheet

    /Jan

  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Jul 08, 2009 @ 11:40
    Tim Geyssens
    1

    Did it like this a while back (on a v3, so not sure if this still works):

    umbraco.presentation.create.dialogHandler_temp.Create("initnodeTypes", autoCreateTemplate, Alias);
    DocumentType newDocType = DocumentType.GetByAlias(Alias);
    newDocType.AddVirtualTab(Alias);
  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Jul 08, 2009 @ 11:49
    Tim Geyssens
    0

    Or try looking at the package installer in the umbraco v4 sourcecode

  • Aaron Powell 1708 posts 3044 karma points c-trib
    Jul 08, 2009 @ 11:52
    Aaron Powell
    1

    Try this:

    var dt = DocumentType.MakeNew(new User(0), "my_doc_type");
    dt.AddPropertyType(DataTypeDefinition.GetDataTypeDefinition(123), "property_1", "Property 1");
    dt.MasterContentType = 12345;
    dt.Save();

    Long story short it's going to be a bit of a pain and a you may end up with magic numbers in your code. The number passed into GetDataTypeDefinition is the ID of the data type you want to use.

    MasterContentType is the parent.

    You don't really have to call save, the only reason I put it there was so that the events fire correctly, saving happens at every other line (see: http://www.aaron-powell.com/blog/july-2009/the-great-umbraco-api-misconception.aspx).

    All the stuff you want is in the cms.dll assembly.

  • Aaron Powell 1708 posts 3044 karma points c-trib
    Jul 08, 2009 @ 11:54
    Aaron Powell
    0

    @Tim - wont your solution only work if you want to use the API and not really use the API?

  • Chris Houston 533 posts 977 karma points MVP admin c-trib
    Jul 08, 2009 @ 19:04
    Chris Houston
    0

    Hi Tim / Slace & Jan,

    Thank you all for your replies, I am going to continue working on this and I will post my final solution when I've cracked it :)

    Cheers,

    Chris

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies