How would you import content into Umbraco page Grid Layout using ContentService?

480 views Asked by At

I'm trying to import my Wordpress blog into Umbraco using the ContentService object. Overall, this works fine but the blog post document type uses a Grid Layout editor for the main body and importing content into that is proving to be a much harder task than I'd have hoped.

Here's the code I'm using:

XDocument loaded = XDocument.Load(Server.MapPath("~/content/my.wordpress.export.xml"));

XNamespace wpns = XNamespace.Get("http://wordpress.org/export/1.2/");
XNamespace contentns = XNamespace.Get("http://purl.org/rss/1.0/modules/content/");
var q = from c in loaded.Descendants("item")
        where c.Element(wpns + "status").Value == "publish"
        select c;

ContentService cs = new ContentService();
var home = cs.GetRootContent().First(b => b.Name == "Home");

var test = q.Take(2); // Just grab a couple to start with...

IContent newPost;

        @foreach (XElement post in test)
        {
            newPost = cs.CreateContent(post.Element("title").Value,
                blog.Id,
                "BlogPost"
                );

            string content = post.Element(contentns + "encoded").Value;
            newPost.SetValue("content", content);
            newPost.SetValue("introduction", post.Element(contentns + "encoded").Value.Substring(0, 240));

            ... and so on
            cs.SaveAndPublishWithStatus(newPost);
        }

The pages are being created just fine; the values are being populated generally but the content field is just empty.

Obviously I'm not doing anything special to account for the different field type in my code and given those fields are basically just JSON arrays, that's possibly my problem. However, I'm hoping there's a simple way to push content into these fields.

Does anyone have any experience or wisdom here?

0

There are 0 answers