Copied to clipboard

Flag this post as spam?

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


  • Nauman 98 posts 118 karma points
    Mar 08, 2010 @ 08:59
    Nauman
    0

    publishing node with nodeid

    Hi I am writing a c# code to get the node / page publish on some event. In my case i am getting list of child nodes of a parent node and then want to publish each child node one by one using umbraco.library.PublishSingleNode. Can you please help me with the following code?

    umbraco.presentation.nodeFactory.Node parentNode = new umbraco.presentation.nodeFactory.Node(int.Parse(1079)); // setting up parent node
    foreach (umbraco.presentation.nodeFactory.Node cnode in parentNode.Children) // looping through all the child nodes
                            {
                                var nodeId = cnode.Id;
                                var nodeName = cnode.Name;
                                Response.Write(nodeId + nodeName);

                                // down here I want to pulish this node


                            }

    Can you please suggest me code under the comments "// down here I want to pulish this node"?

    Thanks

    Nauman

     

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Mar 08, 2010 @ 10:03
    Peter Dijksterhuis
    0

    Hi,

    you can't use nodeFactory to publish a document. The nodeFactory can only be used to get data from published nodes.

    To change and publish nodes, you need to use the Document (in umbraco.cms.businesslogic.web)

                DocumentType documentType = DocumentType.GetByAlias("YourDocumentTypeAlias");

                umbraco.BusinessLogic.User user = new umbraco.BusinessLogic.User(0);

                Document post = new Document(nodeId);

                post.getProperty("yourproperty").Value = yourvalue;

                post.Publish(user);
                umbraco.library.UpdateDocumentCache(post.Id);

    HTH,
    Peter

  • Richard Soeteman 4052 posts 12925 karma points MVP 2x
    Mar 08, 2010 @ 10:09
    Richard Soeteman
    0

    Hi,

    I think umbraco.library.PublishSingledNode only updates the document cache.

    You have to publish in two steps, first step is publish the document which is basically marked for publish. Then you have to update the document cache and then the item is published on  the website. The following snippet does that for you.

    //Get the child Document
    Document doc = new Document(int.Parse(nodeId));
    //Publish the document under Admin account
    doc.Publish(new User(0));
    //Update Document Cache
    umbraco.library.UpdateDocumentCache(doc.Id);

     

    Cheers,

    Richard

  • Nauman 98 posts 118 karma points
    Mar 08, 2010 @ 13:08
    Nauman
    0

    Thanks Peter, Richard

    Richard's method works fine. I visited again here just to ask another question.

    How can I publish the node without using the doctype alias "DocumentType documentType = DocumentType.GetByAlias("YourDocumentTypeAlias");"? because it is possible that each of my node / page uses a different doctype.

    I think my this problem should be resolved using Richards approach, if you guys have any idea on how to publish the node just with the nodeid and without using doctype, that will be helpful.

    Cheers

    Nauman

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Mar 08, 2010 @ 13:21
    Peter Dijksterhuis
    0

    I think you only need the documenttype if you are creating a new document. I probably posted too much code which led to the confusion.

    Richards approach should work just fine, you do not need the documenttype there (but it only works on existing nodes!)

    Again, sorry for the confusion.

    Peter

  • Nauman 98 posts 118 karma points
    Mar 08, 2010 @ 14:55
    Nauman
    0

    Thanks Peter, I picked up the required lines from your code and code of both of you guys work perfectly fine. No need to apologise, you guys provided a great help.

    Thanks

    Nauman

  • Nauman 98 posts 118 karma points
    Mar 09, 2010 @ 09:03
    Nauman
    0

    Peter, All

    I came across another minor issue on this. Please review my following structure.

    Site1
    -index
    -about

    Site2
    -index
    -about

    When I publish the "index" in "Site2" it publishes the "index" in "Site1" though in my code i provide the nodeid toi publish the page. Another thing that might clear my point, I am using Darren plugin to export the pages in html / css, so when my code publishes the "index" in "Site2" it publishes the "index" in "Site1", hence generate the html / css for "index" in "Site1". Any idea what to do with it?

    Nauman

Please Sign in or register to post replies

Write your reply to:

Draft