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"?
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);
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.
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.
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?
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
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;
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
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
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
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
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
is working on a reply...