1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Error posting comment to blog programmatically

Error posting comment to blog programmatically

3 posts, 0 answered
  1. derek
    derek avatar
    37 posts
    Registered:
    15 Jun 2007
    16 Mar 2009
    Link to this post
    Hi,

    I'm writing a script to take data from an existing application, turn the data into blog posts and insert them into out new sitefinity deployment.

    The script works perfectly except for 1 part.

    The data has comments, which I want to put in as comments on the blog posts:

    protected Guid createPost(ContentManager contentManager, blogPost post, Guid ParentID) 
            { 
                 
                // create an empty content  
                IContent newContent = contentManager.CreateContent("text/html"); 
                newContent.Content = post.content; 
                // set meta keys for the content item  
                newContent.SetMetaData("Title", post.title); 
                newContent.SetMetaData("Author", post.author); 
                newContent.ParentID = ParentID; 
     
                newContent.SetMetaData("Publication_Date", post.publicationDate); 
     
     
     
                //save the content  
                contentManager.SaveContent(newContent); 
     
                List<string> listOfTags = new List<String>(); 
                //listOfTags.Add(ClassYear.SelectedItem.Text); 
                listOfTags.Add(post.year); 
                contentManager.SaveTags(newContent.ID, listOfTags); 
     
                foreach (blogPost b in post.comments) 
                { 
     
                    IComment newComment = contentManager.CreateComment(newContent); 
                    newComment.Author = b.author; 
                    newComment.Text = b.content; 
     
                    contentManager.SaveComment(newComment); 
     
                } 
     
     
                return newContent.ID; 
            } 

    When I run this I get an error on the IComment newComment = contentManager.CreateComment(newContent); line:

    The type StagedContent is not supported by this provider.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NotSupportedException: The type StagedContent is not supported by this provider.

    Source Error:


    Line 164:            {
    Line 165:
    Line 166:                IComment newComment = contentManager.CreateComment(newContent);
    Line 167:                newComment.Author = b.author;
    Line 168:                newComment.Text = b.content;
     
    ----

    I'm using the ContentManager from Telerik.Cms.Engine.

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    17 Mar 2009
    Link to this post
    Hi derek,

    You need to get the content again when you create a comment. Give a try to the code below:

                    IContent content = blogsManager.Content.CreateContent("text/html"); 
                    content.ParentID = blog.ID; 
                    content.Content = "this is my custom conten"
                    Guid id = content.ID; 
                    content.SetMetaData("Title""this is my custom content"); 
                    blogsManager.Content.SaveContent(content); 
     
                    IComment comment = blogsManager.Content.CreateComment(blogsManager.Content.GetContent(id)); 
     
                    comment.Author = "Ivan"
                    comment.Text = "MyComment"
                    comment.Visible = true
                    blogsManager.Content.SaveComment(comment); 

    I hope this helps.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team


    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. derek
    derek avatar
    37 posts
    Registered:
    15 Jun 2007
    17 Mar 2009
    Link to this post
    Ivan,

    Thanks, that indeed was the fix. I had thought that the IContent object that I already had would have been valid.

    Thanks for your help as always.
Register for webinar
3 posts, 0 answered