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

Forums / Developing with Sitefinity / How To Get Short News programatically.

How To Get Short News programatically.

5 posts, 2 answered
  1. Adeel Arif
    Adeel Arif avatar
    27 posts
    Registered:
    30 Dec 2009
    14 Jan 2010
    Link to this post
    Hi all,

     I was wondering is there a way that we con get only the text of the news in sitefinity. My requirement is that i have a <div > in the page that must contain top 3 or 4 news latest. and the text showld be of 85 characters.... is there a way that i can do it programatically. i have tried the NewsManager and get the IContents from it and then itrate them to get the items but they seem to give the whole HTML content of the news, while i just only want the text body of the news.... and then make it short up to 85 charcters...

    any help would be really appreciated.
    thanks.


    Regards: ADY
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    14 Jan 2010
    Link to this post
    Hello Adeel Arif,

    You have to get the IContent object  and its  Content. Then you can substring the first 85 chars

    string objectContent = cnt.Content.ToString();
    objectContent.Substring(0, 85);

    if you are using ContentView based control you can use SummarySettings class

    string[] tags = "<b>, <h1>";
    SummarySettings settings = new SummarySettings(SummarySettings.SummaryMode.Words, 10, true, tags);
    newsview.SummarySettings = settings;

    Greetings,
    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.
    Answered
  3. Adeel Arif
    Adeel Arif avatar
    27 posts
    Registered:
    30 Dec 2009
    14 Jan 2010
    Link to this post
    Thank you sooo much Ivan Dimitrov,
     it worked perfectly.......
  4. Adeel Arif
    Adeel Arif avatar
    27 posts
    Registered:
    30 Dec 2009
    14 Jan 2010
    Link to this post
    Can you please also tell me how i can sort them , as latest news first by their date.....?
  5. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    14 Jan 2010
    Link to this post
    Hello Adeel Arif,

    This is the same as setting the summary settings.

    You can give a sort expression to your news view. You can sort by any meta
    newsView.SortExpression = "Publication_Date DESC";
    field which is set to sortable="true" in the web.config:

    Greetings,
    Radoslav Georgiev
    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.
    Answered
Register for webinar
5 posts, 2 answered