More in this section

Forums / Developing with Sitefinity / New MetaData for Blog Post

New MetaData for Blog Post

2 posts, 0 answered
  1. Muhammad Saqib
    Muhammad Saqib avatar
    95 posts
    Registered:
    09 Sep 2009
    19 Nov 2009
    Link to this post
    Hi,

    What i am looking for is to add a new Image field into PostNew/Edit control of blogs. So any image selected will be displayed as Post Header. So what i have done is to add a MetaData field into web.config. (Blogs.ImagePost)

    <add key="Blogs.PostImage" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue="0"  /> 

    but A very annoying situation for me is.

    OnPostEdit.ascx control in admin panel, I have this code..
    1  protected void Page_Load(object sender, EventArgs e) 
    2     {  
    3         saveButton1.Click += new EventHandler(saveButton1_Click); 
    4     } 
    5  
    6     void saveButton1_Click(object sender, EventArgs e) 
    7     { 
    8  
    9         // create new instance of BlogManager 
    10         Telerik.Blogs.BlogManager blogManager = new Telerik.Blogs.BlogManager(); 
    11         // get all blogs 
    12         Telerik.Blogs.IBlog blog = blogManager.GetBlog(new Guid(Request.Params["ParentId"].ToString())); 
    13      
    14         System.Collections.IList li = blog.Posts; 
    15         for (int i = 0; i < li.Count; i++) 
    16         { 
    17             Telerik.Cms.Engine.IContent content = (Telerik.Cms.Engine.IContent)li[i]; 
    18             Guid CID = content.ID; 
    19             if (CID.ToString().Equals(Request.Params["Param"])) 
    20             { 
    21                 //throw new Exception(Image.Text); 
    22                 content.SetMetaData("PostImage", Image.Text); 
    23                 blogManager.Content.SaveContent(content,Telerik.Cms.Engine.ContentStatus.Published); 
    24  
    25                 break
    26             } 
    27         } 
    28  

    but the value for "PostImage" in not set. 
    Even if i go to global.asax file and write this code..

    1 Telerik.Cms.Engine.IContent cnt = (Telerik.Cms.Engine.IContent)e.CommandArguments; 
    2  
    3             if (e.CommandName == "UpdateContent" && cnt.ProviderName == "Blogs"
    4             { 
    5                 string m = cnt.GetMetaData("PostImage").ToString();                
    6                 cnt.SetMetaData("PostImage", m); 
    7                  
    8             } 

    When i check for the value of "m" at line 5,. Its the one what i want . but SetMeaData is not setting up this value for  the post. If i change Line 6 to something like this:
    cnt.SetMetaData("PostImage", "test value");

    Then the "test value" is set. But why the value of variable "m" is not set up in global.asax file????? Or even at PostEdit.ascx file..

    Please do let me know if there is any other good way to achieve the functionality which is i am looking for

    Best Regards,
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    19 Nov 2009
    Link to this post
    Hi Muhammad Saqib,

    The metakeys are automatically persisted, so you do not have to add any additional server code when you use metakeys for backend templates as PostEdit.ascx and PostNew.ascx. The following code works withouth problems at my end

    string m = (string)cnt.GetMetaData("PostImage");               
    cnt.SetMetaData("PostImage", m);

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
2 posts, 0 answered