Try Now
More in this section

Forums / Bugs & Issues / Problems with implementing a public Blog Post Edit control

Problems with implementing a public Blog Post Edit control

2 posts, 0 answered
  1. Klemen Slavič
    Klemen Slavič avatar
    30 posts
    24 Jul 2009
    19 Nov 2010
    Link to this post

    I'm currently having problems following the code examples on the API page, namely:

    In the example provided, the code creates an IContent object, specifies its Content property and Title metadata and then calls SaveContent on the BlogManager.Content instance to save the post.

    When I tried implementing the code, I got a NullReferenceException when the breakpoint hit the SaveContent function, but I'm not able to figure out what object is null, exactly.

    The code in question is:

    01.protected void HandleCommand(object sender, CommandEventArgs e)
    02.    {
    03.        IContent post;
    04.        switch (e.CommandName) {
    05.            case "Delete":
    06.                post = (from IContent p in GetUserBlog().Posts where p.ID.ToString() == BlogPostId.Value select p).FirstOrDefault();
    07.                if (post != null)
    08.                    blogManager.Content.DeleteContent(post);
    09.                break;
    10.            case "Save":
    11.                if (String.IsNullOrEmpty(BlogPostId.Value)) {
    12.                    post = blogManager.Content.CreateContent("text/html");
    13.                    post.ParentID = GetUserBlog().ID;
    14.                } else {
    15.                    post = (from IContent p in GetUserBlog().Posts where p.ID.ToString() == BlogPostId.Value select p).FirstOrDefault();
    16.                    if (post == null) Response.Redirect(BlogPageUrl);
    17.                }
    18.                post.Content = PostContent.Text;
    19.                post.SetMetaData("Title", PostTitle.Text);
    20.                post.Language = Page.UICulture;
    21.                blogManager.Content.SaveContent(post);
    22.                break;
    23.        }
    24.        Response.Redirect(RedirectAfterEditUrl);
    25.    }

    The exception is thrown on line 21.

    Here is the full detail of the exception:

    Server Error in '/mstech.si' Application.

    Object reference not set to an instance of an object.

    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.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    Line 95:                 post.SetMetaData("Title", PostTitle.Text);
    Line 96:                 post.Language = Page.UICulture;
    Line 97:                 blogManager.Content.SaveContent(post);
    Line 98:                 break;
    Line 99:         }

    Source File: c:\Program Files (x86)\Telerik\Sitefinity3.7\WebSites\mstech.si\Sitefinity\UserControls\Blogs\BlogPostEditor.ascx.cs    Line: 97

    Stack Trace:

    [NullReferenceException: Object reference not set to an instance of an object.]
       Telerik.Cms.Engine.ContentIndexProvider.ContentProvider_Executed(Object sender, ExecutedEventArgs e) +808
       System.EventHandler`1.Invoke(Object sender, TEventArgs e) +0
       Nolics.ORMapper.Base.Transaction.Commit(Boolean fCleanIfSuccess) +1326
       Telerik.Cms.Engine.Data.Providers.DefaultProvider.SaveContent(IContent content, Boolean fireEvents) +1203
       Telerik.Blogs.Data.DefaultBlogProvider.SaveContent(IContent content, Boolean fireEvents) +217
       Telerik.Cms.Engine.ContentManager.SavedStagedContent(StagedContent staged, ContentStatus status) +431
       Telerik.Cms.Engine.ContentManager.SaveContent(IContent content, ContentStatus status) +1361
       Sitefinity_UserControls_Blogs_BlogPostEditor.HandleCommand(Object sender, CommandEventArgs e) in c:\Program Files (x86)\Telerik\Sitefinity3.7\WebSites\mstech.si\Sitefinity\UserControls\Blogs\BlogPostEditor.ascx.cs:97
       System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +130
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3691

    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1              
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    25 Oct 2016
    19 Nov 2010
    Link to this post
    Hi Klemen,

    1. Use System.Threading.Thread.CurrentThread.CurrentUICulture = someculture before you create the content item and call CreateConetent method.

    2.You should also set Publication_Date metakey of the content item.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered