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

Forums / Developing with Sitefinity / Pulling News List (or NewsView) by GUIDs

Pulling News List (or NewsView) by GUIDs

14 posts, 0 answered
  1. Jackson
    Jackson avatar
    51 posts
    Registered:
    23 May 2008
    04 Sep 2008
    Link to this post
    I have a query where I am pulling certain GUIDs of a news articles based on the content.

    If I wrap the news view class is there a way to have it only display only the GUID's of the content I have pulled.  I want to do this programatically.

    Thanks for any help you can provide.

  2. Pepi
    Pepi avatar
    981 posts
    Registered:
    08 Dec 2016
    05 Sep 2008
    Link to this post
    Hi Chris Morrow,

    Unfortunately, Sitefinity does not provide a method that gets a list of IContent objects by the specified IDs. Currently, we are working on an advanced new API that will support the required functionality.

    As a workaround you can use the following overload of the GetContent method that returns the content for the specified id:

    public IContent GetContent(   
       Guid id  

    Please note that you should call the method for every GUID in the list of GUIDs. Here is a simple example:

    .ascx
    <%@ Register Assembly="Telerik.News" Namespace="Telerik.News.WebControls" TagPrefix="cc" %> 
       
    <cc:NewsList ID="NewsList1" runat="server"></cc:NewsList> 

    .ascx.cs
        public string ProviderName  
        {  
            get 
            {  
                if (string.IsNullOrEmpty(this.providerName))  
                    return NewsManager.DefaultContentProvider;  
                else 
                    return this.providerName;  
            }  
            set 
            {  
                this.providerName = value;  
            }  
        }  
     
        private NewsManager Manager  
        {  
            get 
            {  
     
                if (this.manager == null)  
                    this.manager = new NewsManager(this.ProviderName);  
                return this.manager;  
            }  
        }  
     
        protected void Page_Load(object sender, EventArgs e)  
        {  
            string[] selectedIds = new string[] { "e6b5ea6d-0162-4638-8d01-6f8475789a13""ae9b51a7-57a5-478a-9881-72456e84dbe1" };  
            List<IContent> source = new List<IContent>();  
     
            for(int i = 0; i <= selectedIds.Length - 1; i++)  
            {  
                IContent cnt = this.Manager.Content.GetContent(new Guid(selectedIds[i]));  
                if(cnt != null)  
                    source.Add(cnt);  
            }  
     
            NewsList1.CustomDataSource = source;  
            NewsList1.DataBind();    
        }  
     
        private string providerName;  
        private NewsManager manager; 

    For more information please refer to the following topic of the Developer manual: GetContent(Guid) Method.

    Hope this helps.

    Greetings,
    Pepi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Jackson
    Jackson avatar
    51 posts
    Registered:
    23 May 2008
    08 Sep 2008
    Link to this post
    That works great but after working on this I realized I needed to do this in a news view.  The problem is that when I set the news view control to be as a item list or a master then it still shows the article.  This is on a page that displays another news view which is in details mode (or single item mode.) How can I have two news views on a page, one showing a list and the other showing details.

    Thanks,
    Chris Morrow
  4. Jackson
    Jackson avatar
    51 posts
    Registered:
    23 May 2008
    08 Sep 2008
    Link to this post
    Ok, forget that last post.  I found a previous thread that had a work around, which worked great.  But now I am using the news view with this same code.  It doesn't seem to accept the source that I am using with getContent.
  5. Pepi
    Pepi avatar
    981 posts
    Registered:
    08 Dec 2016
    09 Sep 2008
    Link to this post
    Hello Chris Morrow,

    CustomDataSource property of the NewsView control does not work properly. So I would suggest you create a custom control (not a user control) that inherits NewsView base class and override CreateDataSource method:

    using System;  
    using System.Data;  
    using System.Configuration;  
    using System.Web;  
    using System.Web.UI;  
    using System.Web.UI.HtmlControls;  
    using System.Web.UI.WebControls;  
    using Telerik.News.WebControls;  
    using Telerik.Cms.Engine;  
    using System.Collections;  
    using System.Collections.Generic;  
     
    namespace Telerik.News.WebControls  
    {  
        public class CustomNewsViewControl : NewsView  
        {  
            protected override IList CreateDataSource()  
            {  
                //return base.CreateDataSource();  
                string[] selectedIds = new string[] { "e6b5ea6d-0162-4638-8d01-6f8475789a13""ae9b51a7-57a5-478a-9881-72456e84dbe1" };  
                List<IContent> source = new List<IContent>();  
     
                for (int i = 0; i <= selectedIds.Length - 1; i++)  
                {  
                    IContent cnt = this.Manager.GetContent(new Guid(selectedIds[i]));  
                    if (cnt != null)  
                        source.Add(cnt);  
                }  
     
                return source;  
            }  
        }  

    Also, you need to register the newly created control in the <toolboxControls> section of the project web.config file to display it the toolbox:

    <toolboxControls> 
        ...  
        <add name="Custom NewsView" section="News" type="Telerik.News.WebControls.CustomNewsViewControl, App_Code" /> 

    Do let us know if you nee any further assistance.

    Sincerely yours,
    Pepi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. Michael Schweigkofler
    Michael Schweigkofler avatar
    2 posts
    Registered:
    28 Mar 2008
    02 Oct 2008
    Link to this post
    Chris Morrow, 9/8/2008 10:26:20 AM
    That works great but after working on this I realized I needed to do this in a news view.  The problem is that when I set the news view control to be as a item list or a master then it still shows the article.  This is on a page that displays another news view which is in details mode (or single item mode.) How can I have two news views on a page, one showing a list and the other showing details.

    Thanks,
    Chris Morrow



    Hi all, I have the same problem, I can't get it to work, can you please post the link of the thread that gives the workaround to solve that inconvenience?

    thanks in advance

  7. Jackson
    Jackson avatar
    51 posts
    Registered:
    23 May 2008
    02 Oct 2008
    Link to this post

    Michael,

    Here is the link to post on the workaround.  Though, I am pretty sure that this is a bug that should be fixed in SF 3.5 which should (and hopefully) be released early next week. 

    http://www.sitefinity.com/support/forums/support-forum-thread/b1043S-behkgm.aspx

    - Chris Morrow

     

  8. Pepi
    Pepi avatar
    981 posts
    Registered:
    08 Dec 2016
    02 Oct 2008
    Link to this post
    Hello,

    We confirm this (using two NewsView controls on a single page) is a bug which is already fixed for the upcoming release of Sitefinity. So I would suggest you wait for the next version (the release is scheduled for the beginning of October).

    Sincerely yours,
    Pepi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  9. Jackson
    Jackson avatar
    51 posts
    Registered:
    23 May 2008
    03 Nov 2008
    Link to this post
    Hello, is there a way for me to sort the content that is pulled in throught the CreateDataSource() method.  I have the property set to sort by Publication_Date but it doesn't seem to effect the sorting when I am adding a custom data source.
  10. Pepi
    Pepi avatar
    981 posts
    Registered:
    08 Dec 2016
    04 Nov 2008
    Link to this post
    Hello Chris Morrow,

    Please use the following overload of GetContent method to get specific subset of content with specified starting position and maximum number, ordered by sorting expression:
    GetContent(int from, int max, string sortExp)

    Do let us know if this helps.

    Best wishes,
    Pepi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  11. Jackson
    Jackson avatar
    51 posts
    Registered:
    23 May 2008
    05 Nov 2008
    Link to this post
    Okay so if I'm using this code,

    protected override IList CreateDataSource()  
            {  
                //return base.CreateDataSource();  
                string[] selectedIds = new string[] { "e6b5ea6d-0162-4638-8d01-6f8475789a13""ae9b51a7-57a5-478a-9881-72456e84dbe1" };  
                List<IContent> source = new List<IContent>();  
     
                for (int i = 0; i <= selectedIds.Length - 1; i++)  
                {  
                    IContent cnt = this.Manager.GetContent(new Guid(selectedIds[i]));  
                    if (cnt != null)  
                        source.Add(cnt);  
                }  
     
                return source;  
            }  


    Where in this code could use that overloaded getcontent method. 
  12. Pepi
    Pepi avatar
    981 posts
    Registered:
    08 Dec 2016
    07 Nov 2008
    Link to this post
    Hi Chris Morrow,

    If I understand correctly you want to sort the list of IContent objects. If it is so then you should implement a custom comparer. Here is a simple example:

    ... 
    protected override IList CreateDataSource()   
            {   
                //return base.CreateDataSource();   
                string[] selectedIds = new string[] { "50a60be5-9fbe-4a99-9aa9-0c6ecb8ae05f""74f2136e-4598-4538-95ef-360c57d9ff2c""d366fce8-6c17-4c17-9a5d-43fea3ecb636" };   
                List<IContent> source = new List<IContent>();   
      
                for (int i = 0; i <= selectedIds.Length - 1; i++)   
                {   
                    IContent cnt = this.Manager.GetContent(new Guid(selectedIds[i]));   
                    if (cnt != null)   
                        source.Add(cnt);   
                } 
     
                ContentComarer comparer = new ContentComarer(); 
                source.Sort(comparer); 
     
                return source;   
            } 
     
            internal class ContentComarer : IComparer<IContent> 
            { 
                #region IComparer<IContent> Members 
     
                public int Compare(IContent x, IContent y) 
                { 
                    return ((DateTime)x.GetMetaData("Publication_Date")).CompareTo((DateTime)y.GetMetaData("Publication_Date")); 
                } 
                #endregion 
            } 
    ... 

    Hope this helps.

    Kind regards,
    Pepi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  13. Viren
    Viren avatar
    41 posts
    Registered:
    03 Aug 2010
    22 Oct 2010
    Link to this post
    Hi Pepi,

    I am asking this here as it is most relevant to my current issue.

    I am trying to follow your reply about creating a custom control and then overriding the CreateDataSource method.
    I am using sitefinity 3.7. I created a folder ProjectName > Usercontrols and added a web control by right clicking on this folder. I however I want to inherit the image gallery so I did this:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public partial class UserControls_customcontrol : Telerik.Libraries.WebControls.ImageGallery
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
    }
     I also registered it inside the config file. but when I try to drag and drop on my template I get this error
    CS0115: 'ASP.usercontrols_sample_customcontrol_ascx.FrameworkInitialize()': no suitable method found to override

    Here is the aspx file:
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="customcontrol.ascx.cs" Inherits="UserControls_customcontrol" %>

    <%@ Register Assembly="Telerik.Libraries" Namespace="Telerik.Libraries.WebControls" TagPrefix="sc" %>
     
    <sc:ImageGallery id="myfirstsamplecontrol" runat="server"></sc:ImageGallery>

    I am struggling even to upload the control and get it run like a noremal image gallery control.  I havent even customized anything yet.

  14. Viren
    Viren avatar
    41 posts
    Registered:
    03 Aug 2010
    22 Oct 2010
    Link to this post
    I got it. I was missing the correct Inherits attribute value. Thanks anyways.
Register for webinar
14 posts, 0 answered