# 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**

```C#
using System;
using System.Linq;
using System.Text.RegularExpressions;
using Telerik.Sitefinity.Blogs.Model;
using Telerik.Sitefinity.Modules.Blogs;

namespace Telerik.Sitefinity.Documentation.CodeSnippets.DevGuide.SitefinityEssentials.Modules.Blogs
{
   public partial class BlogsSnippets
   {
       private void CreateBlogNativeAPI(Guid blogId, string blogTitle)
       {
           BlogsManager blogsManager = BlogsManager.GetManager();
           Blog blog = blogsManager.GetBlogs().Where(b => b.Id == blogId).FirstOrDefault();

           if (blog == null)
           {
               //Create the blog.
               blog = blogsManager.CreateBlog(blogId);

               //Set the properties of the blog.
               blog.Title = blogTitle;
               blog.DateCreated = DateTime.UtcNow;
               blog.LastModified = DateTime.UtcNow;
               blog.UrlName = Regex.Replace(blogTitle.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");

               //Recompiles and validates the url of the blog.
               blogsManager.RecompileAndValidateUrls(blog);

               //Save the changes.
               blogsManager.SaveChanges();
           }
       }
   }
}

```

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**

```C#
using System;
using System.Text.RegularExpressions;

namespace Telerik.Sitefinity.Documentation.CodeSnippets.DevGuide.SitefinityEssentials.Modules.Blogs
{
   public partial class BlogsSnippets
   {
       private void CreateBlogFluentAPI(Guid blogId, string blogTitle)
       {
           var count = 0;
           App.WorkWith().Blogs().Where(b => b.Id == blogId).Count(out count);

           if (count == 0)
           {
               //Create the blog.
               App.WorkWith().Blog().CreateNew(blogId)
                   //Set the properties of the blog.
               .Do(b =>
               {
                   b.Title = blogTitle;
                   b.DateCreated = DateTime.UtcNow;
                   b.PublicationDate = DateTime.UtcNow;
                   b.LastModified = DateTime.UtcNow;
                   b.UrlName = Regex.Replace(blogTitle.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
               })
                   //Save the changes.
               .SaveChanges();
           }
       }
   }
}

```

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.
