Import custom fields

Posted by Community Admin on 05-Aug-2018 00:55

Import custom fields

All Replies

Posted by Community Admin on 12-Mar-2013 00:00

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?

www.sitefinity.com/.../display-author-name-on-blog-s-post

www.sitefinity.com/.../editing-an-existing-data-field

var importedBlogPost = this.Manager.CreateBlogPost();

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

Posted by Community Admin on 14-Mar-2013 00:00

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:

item.GetValue<String>("Title");

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 = "";
               ).SaveChanges();
 
           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.

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

This thread is closed