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

Forums / Developing with Sitefinity / Getting News Item Content ID

Getting News Item Content ID

5 posts, 1 answered
  1. Dan
    Dan avatar
    14 posts
    Registered:
    30 May 2008
    04 Feb 2010
    Link to this post
    I'm trying to access a news item by using NewsManager.Content.GetContent() with a specified ID. My problem is that I'm not sure what's the best way to extract the ID of the currently displayed news item; I've tried a number of solutions (including this one) but it doesn't seem to work; NewsManager.Content.GetContent(itemId) turns out to be null, so obviously itemID is returning an incorrect value or is zero. The end result I'm hoping for is to be able to access the article that's currently being displayed (on a "single news item" page) and return its title and metadata (description, etc).  Any ideas?  We're currently using Sitefinity 3.2, and yes, we are planning to upgrade, but can't do it until certain key features are implemented (which I believe will happen in an upcoming version).
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    05 Feb 2010
    Link to this post
    Hi Dan,

    I am not sure what you exactly pass to the manager to get the content. If you want to get the ID of each item in that is displayed by NewsView control you have to create a custom class that inherits from NewsView and then override SetItemMetaData method where you have access to the content object.

    You can crate a custom control that lists all items. You need to bind your control to a list of IContent objects. Thus you can easily get ID of each IContent object.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
  3. Dan
    Dan avatar
    14 posts
    Registered:
    30 May 2008
    05 Feb 2010
    Link to this post
    Hi Ivan,

    I'm actually referring to the SingleNews control, not NewsView. I need to extract the ID of the news item currently being displayed by the SingleNews control.

    I don't need to list all items, although I see that most of the help available online deals with this. I really just need to find the ID of the currently displayed news item, in order to access its title, description, content, etc., programmatically. I see, from reading the online docs, that SingleNews is deprecated in favour of using NewsView, but, like I said, upgrading isn't an option for us until certain key features have been implemented, which we understand will happen in an upcoming Sitefinity release.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    05 Feb 2010
    Link to this post
    Hello Dan,

    You can get the article ID from the context this.Context.Items["ArticleID"]; Another option is creating a custom class that inherits from SingleNews and get the ID of the item as shown below

    object obj = this.Context.Items["ArticleID"];
    if (obj != null)
        this.articleId = (Guid)((IUrlRewriteData)obj).Data;
    if (this.articleId == Guid.Empty)
        return;
     
    if (string.IsNullOrEmpty(this.providerName))
        this.providerName = NewsManager.DefaultContentProvider;
     
    IContent cnt = base.NewsMngr.Content.GetContent(this.articleId);


    As for the upgrade there are lots of new features and improvements that you can use in 3.7 - new backend architecture, performance optimizations, bug fixes, new modules. I suggest that you should upgrade.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
    Answered
  5. Dan
    Dan avatar
    14 posts
    Registered:
    30 May 2008
    08 Feb 2010
    Link to this post
    Hi Ivan,
    I'm still testing things out to get everything working as I want it, but it looks as though your answer was what I was looking for. Thanks for helping me out with this.
    Cheers
    Dan Jones
Register for webinar
5 posts, 1 answered