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

Forums / General Discussions / How to get the content for more than one content ID

How to get the content for more than one content ID

6 posts, 1 answered
  1. Nagendra
    Nagendra avatar
    28 posts
    Registered:
    07 Jun 2010
    02 Sep 2010
    Link to this post
    Hello All,

    I am using Sitefinity 3.x. I am able to get the content of an item given the ID using the following code:
    IContent content = manager.GetContent(new Guid(id));
    But I am not able to find a way to get the content for more than one ID at the same time. I am trying something like the following:
    List<IMetaSearchInfo> filter = new List<IMetaSearchInfo>();
            filter.Add(new MetaSearchInfo(MetaValueTypes.ShortText, "Id", "31720edf-cd02-4aac-8953-ab4e50a64c0e,e3e8dd04-6e80-494f-b734-018f7bce4182"));
            IList listOfContentItems = manager.GetContent(filter.ToArray());
    But this is not returning me any rows though the provided Ids exist.

    Please help.

    thanks,
    Nagen
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    02 Sep 2010
    Link to this post
    Hello Nagendra,

    MetaSearchInfo works only with meta data. If your ids are added as a metadata you can add separate filter for each id by using filter.Add. Then you can pass filter.ToArray to GetContent method.

    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. Nagendra
    Nagendra avatar
    28 posts
    Registered:
    07 Jun 2010
    02 Sep 2010
    Link to this post
    Hello,
    Thanks for the reply. I am not sure if my Id are added as Meta data or not. I am sure that each and every article present in the CMS will have a Unique Guid. Now I want to get article content given more than one Id.

    Please let me know if I am not clear.

    Thanks,
    Nagendra
  4. Nagendra
    Nagendra avatar
    28 posts
    Registered:
    07 Jun 2010
    02 Sep 2010
    Link to this post
    Hello Ivan,

    I hope the following information will help you understand my problem better:

    Using the following code, I can retrieve the content for a signle ID:
    ContentManger manager = new ContentManager();
    IContent content = manager.getContent(Id);

    Now I want a method where I can get an array of IContent given an Array of Ids.
    Please let me know if something is not clear and please guide on this. This is very urgent for me.

    Thanks,
    Nagendra
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    02 Sep 2010
    Link to this post
    Hi Nagendra,



    There is no such method of ContentManager that accepts guid array to return content items. You can create a custom method that accepts Guid array

    sample code

    protected override void OnPreRender(EventArgs e)
     {
         base.OnPreRender(e);
         //news items
         var item1 = new Guid("85B60627-BF44-4390-8F81-FFF784C34BFA");
         var item2 = new Guid("9F93F595-5CE2-4750-A2BC-F2065E5456AD");
     
         var mylist = GetAllItems(new Guid[] { item1, item2 });
    }
     
     
    public List<IContent> GetAllItems(Guid[] cntIds)
     {
         var items = new List<IContent>();
         var manager = new ContentManager("Generic_Content");
         foreach (Guid g in cntIds)
         {
             if (g != Guid.Empty)
             {
                 var singleItem = manager.GetContent(g);
                 items.Add(singleItem);
             }
         }
          
         return items;
     }




    Greetings,
    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
    Answered
  6. Nagendra
    Nagendra avatar
    28 posts
    Registered:
    07 Jun 2010
    02 Sep 2010
    Link to this post
    Hello Ivan,

    Thanks for the reply.

    Thanks,
    Nagendra
Register for webinar
6 posts, 1 answered