Importing Blog Posts - Unsupported Language "" - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Importing Blog Posts - Unsupported Language ""

  • Importing Blog Posts - Unsupported Language ""
  • a30b501e-37c1-6deb-a958-ff0000446526_error.jpg

    I am migrating an existing blog to Sitefinity using the Fluent API and when I run the following code I get an exception - "Additional information: Unsupported language "". If you want to support this language, please configure your application accordingly."

    • There is only one language set in the configuration.
    • I am explicitly setting the uiCulture and culture to "en" in the web.config - <globalization uiCulture="en" culture="en....
    • Even with the culture set in the web.config, its also set in the blogPost.Title.SetString method
    • This is a fresh install of Sitefinity 7.2.5310.0 to test this code before running in a staging environment

    01.using System;
    02.using System.Linq;
    03.using Telerik.Sitefinity;
    04.using System.Xml.Linq;
    05.using System.Text.RegularExpressions;
    06.using System.Collections.Generic;
    07.using Telerik.Sitefinity.Workflow;
    08.using Telerik.Sitefinity.Blogs.Model;
    09.using System.Globalization;
    10.using System.Threading;
    12.namespace SitefinityWebApp
    14.    public partial class BlogImport : System.Web.UI.Page
    16.        protected void Page_Load(object sender, EventArgs e)
    18.            var blogRSS = XDocument.Load(" OUR RSS FEED  ");
    20.            BlogPost blogPost = null;
    22.            var currentUICulture = CultureInfo.CurrentUICulture;
    23.            Thread.CurrentThread.CurrentUICulture = new CultureInfo(currentUICulture.Name);
    25.            var rssItems = from d in blogRSS.Descendants("item")
    26.                           select d;
    28.            using (var api = App.WorkWith())
    30.                var blog = (from b in api.Blogs().Get()
    31.                            where b.Title == "Blog"
    32.                            select b).FirstOrDefault();
    34.                foreach (var item in rssItems.ToList())
    36.                    blogPost = new BlogPost();
    37.                    blogPost.Title.SetString(Thread.CurrentThread.CurrentUICulture, item.Element("title").Value);
    38.                    CreateBlogPost(blog.Id, blogPost);
    43.        private void CreateBlogPost(Guid parentBlogId, BlogPost blogPost)
    45.            var count = 0;
    46.            Guid masterBlogPostId = Guid.NewGuid();
    48.            App.WorkWith().Blogs().Where(b => b.Id == parentBlogId).Count(out count);
    50.            if (count > 0)
    52.                App.WorkWith().Blog(parentBlogId).CreateBlogPost()
    53.                .Do(p =>
    55.                    masterBlogPostId = blogPost.Id;
    56.                    p.Title = blogPost.Title;
    57.                    p.DateCreated = DateTime.UtcNow;
    58.                    p.PublicationDate = DateTime.UtcNow;
    59.                    p.LastModified = DateTime.UtcNow;
    60.                    p.Content = blogPost.Content;
    61.                    p.UrlName = Regex.Replace(blogPost.Title.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
    62.                ).SaveChanges();
    64.                var bag = new Dictionary<string, string>();
    65.                bag.Add("ContentType", typeof(BlogPost).FullName);
    66.                WorkflowManager.MessageWorkflow(masterBlogPostId, typeof(BlogPost), null, "Publish", false, bag);

  • Hello Neil,

    You can create a blog post using the native or fluent API. You can read more about the two approaches in this documentation article

    So according to the documentation here is how you have to change your code in order to get it working:

    using System;
    using System.Linq;
    using Telerik.Sitefinity;
    using System.Xml.Linq;
    using System.Text.RegularExpressions;
    using System.Collections.Generic;
    using Telerik.Sitefinity.Workflow;
    using Telerik.Sitefinity.Blogs.Model;
    using System.Globalization;
    using System.Threading;
    namespace SitefinityWebApp
        public partial class BlogImport : System.Web.UI.Page
            protected void Page_Load(object sender, EventArgs e)
                var blogRSS = XDocument.Load(" OUR RSS FEED  ");
                BlogPost blogPost = null;
                var currentUICulture = CultureInfo.CurrentUICulture;
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(currentUICulture.Name);
                var rssItems = from d in blogRSS.Descendants("item")
                               select d;
                using (var api = App.WorkWith())
                    var blog = (from b in api.Blogs().Get()
                                where b.Title == "Blog"
                                select b).FirstOrDefault();
                    foreach (var item in rssItems.ToList())
                        var blogPostTitle = item.Element("title").Value;
                        CreateBlogPost(blog.Id, blogPostTitle);
            private void CreateBlogPost(Guid parentBlogId, string blogPostTitle)
                var count = 0;
                Guid masterBlogPostId = Guid.NewGuid();
                App.WorkWith().Blogs().Where(b => b.Id == parentBlogId).Count(out count);
                if (count > 0)
                    .Do(p =>
                        masterBlogPostId = p.Id;
                        p.Title = blogPostTitle;
                        p.DateCreated = DateTime.UtcNow;
                        p.PublicationDate = DateTime.UtcNow;
                        p.LastModified = DateTime.UtcNow;
                        p.Content = blogPostContent; // add some content
                        p.UrlName = Regex.Replace(blogPostTitle.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
                    var bag = new Dictionary<string, string>();
                    bag.Add("ContentType", typeof(BlogPost).FullName);
                    WorkflowManager.MessageWorkflow(masterBlogPostId, typeof(BlogPost), null, "Publish", false, bag);

    Nadezhda Petrova
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
  • Great, thanks!    

    On related note I added a DateTime publishedDate parameter to  the CreateBlogPost method and send it in using var publishedDate = DateTime.Parse(item.Element("pubDate").Value); in the fluent API call I am setting p.DateCreated, p.PublicationDate and p.LastModified to this publishedDate parameter but it is being persisted to the database as the current date time


  • Hello Neil,

    Sitefinity sets the DateCreated/LastModified automatically to the current date once the item is created and this cannot be further modified. Sitefinity sets it automatically to current date once the item is created independent of the value we have set in code and then updates the date every time the item is modified. This date cannot be modified to a date in the past.

    This is the behavior by design in order to allow the admin users to track when an item has been created and when this item has been last modified in Sitefinity.

    What I can suggest as a workaround is to create a custom field for the Blog post items and specify it to be of type Date and Time. Then when creating the blog post through the API, you can set the value of this custom field to be the DateCreated date of the original blog post.

    Nadezhda Petrova
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items