public JsonResult AddBlog(Blog blog) { string textfile = blog.BlogBody; Users user = JsonConvert.DeserializeObject <Users>(Convert.ToString(Session["User"])); string Blogurl = Sanitizer.GetSafeHtmlFragment(blog.Title).Trim().Replace(' ', '-').Replace(".", ""); Blog myblog = new Blog() { Title = blog.Title, Tags = blog.Tags, BlogBody = blog.BlogBody, Date = DateTime.Now, User = new Users() { Name = user.Name, Email = user.Email, Id = user.UserID }, BlogUrl = Blogurl, BlogMonth = DateTime.Now.ToString("MMM-yyyy"), VideoEmbed = blog.VideoEmbed, AuthorId = Convert.ToString(user.UserID), }; var id = _blogrepo.AddBlog(myblog); string fullPath = Server.MapPath("/BlogFiles/Blog_" + id + ".txt"); using (StreamWriter writer = new StreamWriter(fullPath)) { writer.WriteLine(textfile); } return(Json(new { Success = true }, JsonRequestBehavior.AllowGet)); }