Create blogs

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

  1. Check whether the blog already exists.

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

  2. Create the blog.

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

  3. Set the required properties.

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

    • Title
    • LastModified
    • DateCreated
    • UrlName

    You can also set any other properties in this step.

  4. Save the blog.

    Save all changes that you have made to the blog.

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

Creating a blog with predefined ID

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

Native API

First, you get an instance of the BlogsManager class. You check whether a blog with the same ID already exists. To create the blog, you call the CreateBlog method of the BlogsManager class and pass the specified ID. You can create a blog with either predefined or auto-generated ID depending on which overload of the method you use. Then, you set the properties of the blog object. It is recommended to set at least the following properties: Title, UrlName, LastModified, DateCreated. Finally, to save the blog, you call the SaveChanges method of the manager.

Fluent API

First, you check whether a blog with the same ID already exists. To create the blog, you call the CreateNew method of the singular facade. You can create a blog with either predefined or auto-generated ID depending on which overload of the method you use. To set the properties of the blog, you call the Do method of the facade. Finally, you save the changes.

Was this article helpful?

Next article

Query blogs