Create blog posts

When creating a blog post, you must perform the following:

  1. Check whether the blog post already exists.

    Before you create the blog post, you must check whether a blog post with the same ID already exists.

  2. Create the blog post.

    If the blog post does not exist, you create a new blog post with the specified ID.

  3. Specify the parent blog of the blog post.

    Specify to which blog the blog post belongs.

  4. Set the required properties.

    When creating a new blog post, it is recommended to set at least the following properties:

    • Title
    • Content
    • LastModified
    • DateCreated
    • UrlName

    You can also set any other properties (e.g. Author, Summary, etc.) in this step.

  5. Save the blog post.

    Save all changes that you have made to the blog post.

  6. Publish the blog post.

    Finally, you publish the blog post using the workflow manager.

The example below shows you how to create blog post with predefined ID.

NOTE: The ID argument is assigned to the master version of the blog post. For more information about the different versions of a blog post, see For developers: Content lifecycle.

Creating a blog post with predefined ID

The following code creates a blog post with the specified ID, Title and Content.

Native API


First, you get an instance of the BlogsManager class. You check whether a blog post with the same ID already exists. To create the blog post, you call the CreateBlogPost method of the BlogsManager class. You can create a blog post with either predefined or auto-generated ID depending on which overload of the method you use. The method returns the master version of the blog post. Then, you set the properties of the master version. It is recommended to set at least the following properties: Title, Content, UrlName, LastModified, PublicationDate, DateCreated. To save the changes, you call the SaveChanges method of the manager. Finally, to publish the blog post, you call the MessageWorkflow method of the WorkflowManager class and pass the required parameters.

Fluent API


First, you check whether a blog post with the same ID already exists. Then, if it does not exist, you create the blog post by calling the CreateBlogPost method of the singular facade of the parent blog. The ID argument is assigned to the ID master version of the item. To set the properties of the blog post, you call the Do method of the facade. Then, you save the changes. Finally, to publish the blog post, you call the MessageWorkflow method of the WorkflowManager class and pass the required parameters.

Was this article helpful?

Next article

Query blog posts