More in this section

Forums / Developing with Sitefinity / Getting Content in Code

Getting Content in Code

7 posts, 0 answered
  1. Armysniper
    Armysniper avatar
    126 posts
    Registered:
    03 Mar 2005
    26 Jan 2009
    Link to this post
    I read the article on the many ways to use GetContent to find a piece of Generic Content. Is there some code that someone has for getting content if you already know the title or something. Seems like there should be an easier way to get content than what is shown in the code. I am still reading through the examples but wanted to know if someone came up with something that was easier.
  2. Kameo
    Kameo avatar
    13 posts
    Registered:
    23 Feb 2006
    26 Jan 2009
    Link to this post
    I don't know if this is easier but it's somewhat simplified hope it helps.  The result is an IList of IContent objects that match your MetaSearchInfo criteria.

    [code]

     

    //Using the Generic Content provider you can pass in some other provider if you wanted

     

     

    ContentManager mgr = new ContentManager("Generic_Content");

     

     

    //Creating a list of filters to search by

     

     

    List<IMetaSearchInfo> myFilters = new List<IMetaSearchInfo>();

     

     

    //Create a filter I use Name as the field I'm searching

     

     

    MetaSearchInfo filter1 = new MetaSearchInfo(MetaValueTypes.ShortText, "Name", "value to search for", SearchCondition.Equal);

     

    myFilters.Add(filter1);

     

    //myList is a list of the results based on the search filters

     

     

    IList myList = mgr.GetContent(myFilters.ToArray());

     

    [/code]
  3. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    27 Jan 2009
    Link to this post
    Hi Kameo,

    Thank you for providing an answer. I have updated your Telerik account for that.

    Sincerely yours,
    Georgi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  4. Armysniper
    Armysniper avatar
    126 posts
    Registered:
    03 Mar 2005
    27 Jan 2009
    Link to this post
    Thanks for the help. That seams like alot of code for something that should be as easy as something like this (pseudo code):

    ContentManager mgr = new ContentManager ("Generic_Content");

    mgr.GetContent("My Title");


    I know a very specific article I want to pull down. I am using Generic Content as a location for system text and introductory help for my controls. For example, in my job board controls I want to introduce a section with some help so people are not confused. I would like to use the Generic content types to allow my content editors a crack at creating the help text.

    There is no easier way to simply grab content you have created if you know what the title is or something than this?


  5. Kameo
    Kameo avatar
    13 posts
    Registered:
    23 Feb 2006
    27 Jan 2009
    Link to this post

    I know it seems like a lot of code just to grab something you know the name of, the problem is there's a lot of meta fields to search by so you need to be specific.    All the MetaSearchInfo part does it tell the system which meta field to search in (Name, Description, etc as defined in your web.config) and  how to compare that field to the value you're looking for.

    Is there a reason you need to grab the content programatically?  Could you just drag the Generic Content control onto your job board page and then choose from the shared content the exact help module your content editors created? 


    Good luck!
    -kameo
  6. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    27 Jan 2009
    Link to this post
    i think the problem comes from the flexibility of the meta field. remember that title is a meta field, and not part of the actual content item interface (IContent). The title isn't something that is hard-coded or universal to sitefinity. where you might use "title" I might have "name" or "heading" and it might not even be text, I might use a date or url instead...

    I agree tho that some overloads to the GetContent might help simplify things, or perhaps a GetContentByMeta(string field, object value) and have it internally create the query to make things easier...

  7. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    29 Jan 2009
    Link to this post
    Hi,

    This is something that should be available with the new API we are working on. Sitefinity 4.0 will provide new methods for getting the content and new API in general.

    Best wishes,
    Georgi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Register for webinar
7 posts, 0 answered