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);
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.
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
Aa, that's it! Thank you!
By the way, the reason it didn't publish was because I forgot some required fields. Doh!
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
Jan, do you now what function to use to edit and save a node? I can't find anything appropriate.
Never mind, I found it. GetById()
is working on a reply...