Try Now
More in this section

Forums / Sitefinity SDK / Import custom fields

Import custom fields

2 posts, 0 answered
  1. Emmett
    Emmett avatar
    5 posts
    18 Oct 2012
    12 Mar 2013
    Link to this post

    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?

  2. Stefani Tacheva
    Stefani Tacheva avatar
    718 posts
    19 Oct 2016
    14 Mar 2013
    Link to this post
    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.

2 posts, 0 answered