More in this section
Forums / Developing with Sitefinity / Displaying List Item Content [Blog Posts] Programatically Using ASP

Displaying List Item Content [Blog Posts] Programatically Using ASP

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
2 posts, 1 answered
  1. MBA
    MBA avatar
    11 posts
    08 Jul 2008
    12 Sep 2011
    Link to this post
    Hi All,

    After a mammoth session learning (and subsequently patching) SiteFinity 4.2, the last hurdle I need to overcome is the ability to get the content of a List Item and assign it to an ASP (C#) variable.

    Essentially I'd like to be able to loop over all given List Items (in this case, blog posts) and assign the content of the ListItem (Blog Post) to a C# variable which I can then manipulate.

    Does anyone have any experience doing this? I've followed an old (SF3.x, Visual Basic) how-to and managed (I think!) to translate it to SF4.2 and C#. The code appears below.

    Unfortunately, I cannot get the code to load anything into the list. Visiting the page in a browser gives the following error (ASP gives Line 6, below, as the point of occurance):

    I have a feeling I might need to use a Linq Query to extract the posts I want, however I'm not so sure how to go about it. Can anyone give me a pointer or helping hand please?

    Exception Details: Telerik.Sitefinity.SitefinityExceptions.ItemNotFoundException: You are trying to access item that no longer exists. The most probable reason is that it has been deleted by another user.

    Stack Trace: 

    [ItemNotFoundException: You are trying to access item that no longer exists. The most probable reason is that it has been deleted by another user.]
       DynamicModule.ns.Wrapped_OpenAccessListsDataProvider_e1f3a1b538c2464d870ac9deb2d5665e.GetList(Guid id) +253
       Telerik.Sitefinity.Modules.Lists.ListsManager.GetList(Guid id) +45
       SitefinityWebApp.Controls.TestBlog.Page_Load(Object sender, EventArgs e) in C:\inetpub\wwwroot\pp\Controls\TestBlog.aspx.cs:23
       System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
       System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
       System.Web.UI.Control.OnLoad(EventArgs e) +91
       System.Web.UI.Control.LoadRecursive() +74
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

    01.protected void Page_Load(object sender, EventArgs e)
    02.        {
    03.            /* Setup array to hold posts */
    04.            string[] strContent = null;
    06.            /* Define new list manager for access to lists */
    07.            Telerik.Sitefinity.Modules.Lists.ListsManager mgrList = new Telerik.Sitefinity.Modules.Lists.ListsManager();
    09.            /* Define GUID of list to load */
    10.            Guid searchForGuid = new Guid("854FD531-2B15-4277-B616-49A36D7FBB85");
    12.            /* Load list into new SiteFinity list */
    13.            Telerik.Sitefinity.Lists.Model.List objLists = mgrList.GetList(searchForGuid);
    15.            /* Define a list item for use later */
    16.            Telerik.Sitefinity.Lists.Model.ListItem thisItem = new Telerik.Sitefinity.Lists.Model.ListItem();
    18.            /* Load list into more system friendly model */
    19.            System.Collections.IList sysList = objLists.ListItems.ToList();
    21.            /* Loop over system friendly list and write content to array */
    22.            foreach ( int r in sysList)
    23.            {
    24.                int c = 0;
    25.                /* Assign content to array */
    26.                strContent[c]=thisItem.Content;
    28.                /* Output something to the screen */
    29.                Response.Write("Loop: " + c.ToString() + "<br />");
    30.                Response.Write(strContent[c]);
    31.                c++;
    32.            }
    33.        }

  2. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    18 Sep 2017
    15 Sep 2011
    Link to this post
    Hello Jeff,

    Here is the API code that will get the contents of the list item.

    String myListName = "List";
                ListsManager manager = ListsManager.GetManager();
                Telerik.Sitefinity.Lists.Model.ListItem currentItem = manager.GetListItems()
                    .Where(i => i.Parent.Title == myListName)
                if (currentItem != null)
                    var content = currentItem.GetValue("Content");
    //Content is the name of the field in list that represents the editor where you enter contents
    You can review all field names by going to Lists module entering a list and in the right sidebar clicking custom fields for lists. There is a tab with all the default field names.

    Stanislav Velikov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 1 answered