Publishing Blog Post Using API

Andre Pfanz asked on April 15, 2016 18:06

We are using Kentico v9 and are importing blog posts from Wordpress into Kentico. The post itself is being imported but is not being published. Here's the code being used to import

//Create a new tree node of type blog post
var postNode = TreeNode.New(BLOG_POST_PAGE_TYPE);
postNode.DocumentPageTemplateID = BLOG_TEMPLATE_ID;
//Replace carriage returns in blog post content with <br>, get rid of double quotes
string content = (string)postRow.wp_post_content;
content = content.Replace("\r\n", "<br>").Replace("\"\"", "");
//Assign the blog post title, date and content
postNode["BlogPostTitle"] = (string)postRow.wp_post_title;
postNode["BlogPostDate"] = postRow.wp_post_date;
postNode["BlogPostBody"] = postRow.wp_post_content;
postNode["BlogPostAllowComments"] = (postRow.wp_comment_status.ToString() == "closed") ? false : true;
postNode.DocumentCulture = monthNode.DocumentCulture;
//Publish the blog post
TreeProvider treeProvider = new TreeProvider();
WorkflowManager workflowManager = WorkflowManager.GetInstance(treeProvider);
WorkflowInfo workflow = workflowManager.GetNodeWorkflow(postNode);
if (workflow != null)
//Add the blog post node under the month node

I found out the postNode node does not have a workflow assigned to it. How do I assign a workflow using the API so I can publish the blog post?

Correct Answer

Brenden Kehren answered on April 15, 2016 18:22

Take a look at this post. I have in there some pretty easy setup of publishing a page. What it looks like in your example is you're trying to apply workflow before the document is created.

The simple approach is like so (don't check for workflow):

postNode.Publish(); // automatically sets it to the last publish step in the work flow
1 votesVote for this answer Unmark Correct answer

Recent Answers

Andre Pfanz answered on April 15, 2016 18:34

Thanks Brenden

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.