Importing Blog Posts - Unsupported Language ""

Posted by Community Admin on 05-Aug-2018 17:14

Importing Blog Posts - Unsupported Language ""

All Replies

Posted by Community Admin on 05-Nov-2014 00:00

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;
11. 
12.namespace SitefinityWebApp
13.
14.    public partial class BlogImport : System.Web.UI.Page
15.    
16.        protected void Page_Load(object sender, EventArgs e)
17.        
18.            var blogRSS = XDocument.Load(" OUR RSS FEED  ");
19. 
20.            BlogPost blogPost = null;
21. 
22.            var currentUICulture = CultureInfo.CurrentUICulture;
23.            Thread.CurrentThread.CurrentUICulture = new CultureInfo(currentUICulture.Name);
24. 
25.            var rssItems = from d in blogRSS.Descendants("item")
26.                           select d;
27. 
28.            using (var api = App.WorkWith())
29.            
30.                var blog = (from b in api.Blogs().Get()
31.                            where b.Title == "Blog"
32.                            select b).FirstOrDefault();
33. 
34.                foreach (var item in rssItems.ToList())
35.                
36.                    blogPost = new BlogPost();
37.                    blogPost.Title.SetString(Thread.CurrentThread.CurrentUICulture, item.Element("title").Value);
38.                    CreateBlogPost(blog.Id, blogPost);
39.                
40.            
41.        
42. 
43.        private void CreateBlogPost(Guid parentBlogId, BlogPost blogPost)
44.        
45.            var count = 0;
46.            Guid masterBlogPostId = Guid.NewGuid();
47. 
48.            App.WorkWith().Blogs().Where(b => b.Id == parentBlogId).Count(out count);
49. 
50.            if (count > 0)
51.            
52.                App.WorkWith().Blog(parentBlogId).CreateBlogPost()
53.                .Do(p =>
54.                
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();
63. 
64.                var bag = new Dictionary<string, string>();
65.                bag.Add("ContentType", typeof(BlogPost).FullName);
66.                WorkflowManager.MessageWorkflow(masterBlogPostId, typeof(BlogPost), null, "Publish", false, bag);
67.            
68.        
69.    
70.

Posted by Community Admin on 07-Nov-2014 00:00

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)
            
                App.WorkWith().Blog(parentBlogId).CreateBlogPost()
                .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_]+", "-");
                ).SaveChanges();
  
                var bag = new Dictionary<string, string>();
                bag.Add("ContentType", typeof(BlogPost).FullName);
                WorkflowManager.MessageWorkflow(masterBlogPostId, typeof(BlogPost), null, "Publish", false, bag);
            
        
    


Regards,
Nadezhda Petrova
Telerik
 
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
 

Posted by Community Admin on 07-Nov-2014 00:00

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

 

Posted by Community Admin on 11-Nov-2014 00:00

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.

Regards,
Nadezhda Petrova
Telerik

 
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
 

This thread is closed