Import custom fields - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Import custom fields

  • Import custom fields
  • I need to add some custom fields, specifically author, imageUrl (for thumbnails) and maybe an author twitter id and facebook id etc. I see two different approaches here, is the latter just for displaying these new fields in my posts? Also, I need to import a set of blog posts as Sitefinity posts but set some of these properties on the post. I added 'Author' following the steps in the first url and noticed a bunch of config changes but I am unclear on what do to set this property on the blog object in code, is there a special method for setting the custom properties?

    var importedBlogPost = this.Manager.CreateBlogPost();

    importedBlogPost.Title = post.Title; // now what? I need to set my custom field properties some how?

  • Hi Emmett,

    For custom fields we have our extension methods GetValue and SetValue which help retrieve and set the custom field values accordingly. For example, in order to retrieve the title value you could say:


    Title is the name of the custom field.

    Here is a sample of how we add custom fields to a new blog post:

    App.WorkWith().Blog().CreateBlogPost(postId).Do(bp =>
                       bp.Title = txtPostTitle;
                       bp.PublicationDate = pubDate;
                       bp.ExpirationDate = expDate;
                       bp.UrlName = bp.Id.ToString();
                       bp.DateCreated = pubDate;
                       bp.ApprovalWorkflowState.Value = "Published";
                       bp.SetValue("City", city);
                       bp.SetValue("isPrivate", isprivate);
                       string Description = "";
               var bag = new Dictionary<string, string>();
               bag.Add("ContentType", typeof(BlogPost).FullName);
               WorkflowManager.MessageWorkflow(postId, typeof(BlogPost), null, "Schedule", true, bag);

    Please note that you'll need top add:
    using Telerik.Sitefinity.Model;

    in your class in order to access the GetValue extension method.

    To add custom fields to blog posts, go to Content -> Blogs ->YourBlog to access the posts screen. On the right sidebar, click the CustomFields for posts link to go to the page where you can add your new custom fields.

    Stefani Tacheva
    the Telerik team
    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.