Copied to clipboard

Flag this post as spam?

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


  • Peter S 169 posts 587 karma points
    Jun 04, 2014 @ 16:24
    Peter S
    0

    Create node in code

    I use the code below to create nodes in 7.1. The pages are created but not published. Any idea why this is? Also, Visual Studio tells me the code is obsoloete. Is there a newer/better way to do it? This is all I could find.

    DocumentType dt = DocumentType.GetByAlias("TextPage");
    
    umbraco.BusinessLogic.User u = new umbraco.BusinessLogic.User(0);
    
    Document doc = Document.MakeNew("Page name", dt, u, parentNodeID);
    
    doc.getProperty("textProperty").Value = "Lorem ipsum dolor";
    
    doc.Publish(u);
    umbraco.library.UpdateDocumentCache(doc.Id);
  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jun 04, 2014 @ 16:30
    Jan Skovgaard
    100

    Hi Peter

    Seems like you're using the v4 way of doing things....(before 4.10 was released)

    Make sure to use the ContentService, which you can read more about here http://our.umbraco.org/documentation/Reference/Management-v6/Services/

    Hope this helps.

    /Jan

  • Peter S 169 posts 587 karma points
    Jun 04, 2014 @ 16:57
    Peter S
    0

    Aa, that's it! Thank you!

    By the way, the reason it didn't publish was because I forgot some required fields. Doh!

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jun 04, 2014 @ 18:06
    Jan Skovgaard
    0

    Hi Peter

    Happy to help - Remember to mark the issue as solved so others can jump straight to the answer if they should stumble upon the same issue.

    Have fun with the services :)

    /Jan

  • Peter S 169 posts 587 karma points
    Jun 11, 2014 @ 09:40
    Peter S
    0

    Jan, do you now what function to use to edit and save a node? I can't find anything appropriate.

  • Peter S 169 posts 587 karma points
    Jun 11, 2014 @ 10:08
    Peter S
    0

    Never mind, I found it. GetById()

Please Sign in or register to post replies

Write your reply to:

Draft