Try Now
More in this section

Forums / Developing with Sitefinity / Trouble importing legacy News Items

Trouble importing legacy News Items

3 posts, 0 answered
  1. Doug
    Doug avatar
    34 posts
    20 Apr 2010
    27 Apr 2010
    Link to this post
         I am trying to import quite a few legacy news articles into SiteFinitiy using the News API but have hit a bit of a wall.

    I have followed examples found at both of the following links with no luck:

    Here is my secnario: 

    I have setup a WCF ReST based Web Service inside a site that uses SiteFinity.  The code for the the WCF service resides inside of an assembly that I wrote which references all of the necessary Sitefinity Assemblies and resides inside the /bin of the website directory along with the Sitefinity Assemblies.   All of my processes are pretty vanilla: XML comes into the service, I have a parser that parses the data out into an IContent and I attempt to save the data.  The save is where the process fails.  Code Follows:



    NewsManager mgr = new NewsManager("News");
    IContent content = mgr.Content.CreateContent("text/html");
    content.Content = Node.SelectSingleNode("Content").InnerText;
    content.Status = ContentStatus.Published;
    content.SetMetaData("Title", Node.SelectSingleNode("Title").InnerText);
    content.SetMetaData("Summary", Node.SelectSingleNode("Summary").InnerText);
    content.SetMetaData("Author", Node.SelectSingleNode("Author").InnerText);
    content.SetMetaData("Source", Node.SelectSingleNode("Source").InnerText);
    content.SetMetaData("Title", Node.SelectSingleNode("Title").InnerText);
    content.SetMetaData("Publication Date", Convert.ToDateTime(Node.SelectSingleNode("PublicationDate").InnerText));
    content.SetMetaData("Expiration Date", Convert.ToDateTime(Node.SelectSingleNode("ExpirationDate").InnerText));
    content.SetMetaData("Thumbnail", Node.SelectSingleNode("Thumbnail").InnerText);
    content.SetMetaData("Category", Node.SelectSingleNode("Category").InnerText);

    When I call SaveContent I get an Object Reference not set to an instance of an object error with the following stack:


    at Telerik.Cms.Engine.StagedContent.Publish(IVersionItem item)

    at Telerik.Cms.Engine.ContentManager.SaveContent(IContent content, ContentStatus status)

    at Telerik.Cms.Engine.ContentManager.SaveContent(IContent content)
    at [My Namespaces]...

    Any help would be greatly appreciated.

    Any help would be greatly appreciated.

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    12 Sep 2017
    28 Apr 2010
    Link to this post
    Hello Doug,

    The stack is not enough to say what the problem is. There is some value that is null. You could also try to remove   content.Status = ContentStatus.Published;  and set the status when the item is being saved mgr.Content.SaveContent(content, ContentStatus.Published);

    Also you are setting the tile twice, so you could remove the 9 line of your code.

    Try using ContentManager mgr = new ContentManager("News"); instead of NewsManager. By default Publication_Date and Expiration_Date have underscore in the names.

    Kind regards,
    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.
  3. Doug
    Doug avatar
    34 posts
    20 Apr 2010
    28 Apr 2010
    Link to this post
    Hi Ivan,
       Thanks for your response.  Unfortunately none of your suggestions work. After my initial post yesterday I began to work back through and replaced the dynamic parsing with simple static content but even this seemed to fail.  Rather than bore you with the process that I went through here is what I noticed:

    Making a request directly to the webservice through HTTP would cause the Object Reference error, however, creating an instance of the class that contains the logic for the WCF service and then calling it driectly from a page within my SiteFinity site worked flawlessly. Since I obviously don't have the actual source code for SiteFinity I was a little blind as to what was going on in the Telerik assemblies exactly so I started poking around. After hours of reflection and going WTF, here is what I came up with:

    In the Telerik.Cms.Engine namespace there is a class called StaggedContent that has two Publish methods.  The one that I was concerned with was the one that had the following signature:

    void Publish(IVersionItem item)

    Somewhere in this method an object reference exception was being thrown when the News API was called via WCF. After reading through the method I noticed the following code near the top of the method:

    if (HostingEnvironment.IsHosted)
        applicationPath = HttpContext.Current.Request.ApplicationPath;
        applicationPath = this.ApplicationName;
    The issue lies in call to Request.ApplicationPath; because of how I write my WCF Services I don't enable AspNetCompatibility unless I need to...but because the underlying SiteFinity API is making these types of calls AspNetCompatibility must be enabled both on the Service and in the Web.Config.  Once I enabled these everything ran smoothly.


Register for webinar
3 posts, 0 answered