More in this section
Forums / Developing with Sitefinity / Fetch and Display Content Item

Fetch and Display Content Item

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, 0 answered
  1. Martin
    Martin avatar
    5 posts
    19 Dec 2007
    06 Jun 2011
    Link to this post

    I know how to get a content item from the CMS database....

    In several situations I'd like to retrieve some CMS content and
    display it in a radWindow dialog inside an HTML container (Div,etc.) on a standard ASPX page.

    I can fetch the content item and display it.
    However any images are not rendered...
    Is there a means to display/render the content images ?

    I've attached an image to illiustrate....
    Any help appreciated!?

    (My current code is below)



                Dim contentManager As New Telerik.Cms.Engine.ContentManager()
                Dim listOfContentItems As IList = contentManager.GetContent()
                If listOfContentItems.Count > 0 Then
                    For Each contentItem As Telerik.Cms.Engine.IContent In listOfContentItems
                        If contentItem.GetMetaData("Name") = "Help - Filter Hints" Then
                            Me.LabelHelp.Text = contentItem.Content
                        End If
                End If

  2. Martin
    Martin avatar
    5 posts
    19 Dec 2007
    07 Jun 2011
    Link to this post

    I've sorted my problem...
    To resolve images from generic content
    this code may also be useful to others....

    See also this post which helped me solve it...

    Me.Label1.Text = ResolveContent(GetContentItem("Help - Filter Hints"))
        ' Takes a Generic Content Item, Resolves any Images and Returns the updated Content
        Public Function ResolveContent(ByVal strContent As String) As String
            Dim sbResolved As New StringBuilder()
            Dim startPos As Integer = strContent.IndexOf("<img")
            Do While startPos <> -1
                ' Find the Sitefinity [Libraries] string
                Dim libraryPos As Integer = strContent.IndexOf("[Libraries]", startPos)
                If libraryPos <> -1 Then
                    Dim quotePos As Integer = strContent.IndexOf(Chr(34), libraryPos)
                    ' Resolve the URL
                    Dim unresolvedUrl As String = strContent.Substring(libraryPos, quotePos - libraryPos)
                    ' eg. GetItemUrl("[Libraries]6f93dc67-662c-40a9-b8f3-181620e01e99")
                    sbResolved.Replace(unresolvedUrl, GetItemUrl(unresolvedUrl))
                End If
                startPos = strContent.IndexOf("<img", startPos + 1)
            Return sbResolved.ToString
        End Function
        ' Resolve a sitefinity Image URL
        ' eg. "[Libraries]6f93dc67-662c-40a9-b8f3-181620e01e99"
        Public Function GetItemUrl(ByVal unresolvedUrl As String) As String
            Dim urlResolved As String = Nothing
            If unresolvedUrl.StartsWith("[") Then
                Dim idx As Integer = unresolvedUrl.IndexOf("]")
                Dim provider As String = unresolvedUrl.Substring(1, idx - 1)
                Dim strId As String = unresolvedUrl.Substring(idx + 1)
                Dim id As New Guid(strId)
                If Telerik.Cms.Engine.ContentManager.Providers.ContainsKey(provider) Then
                    Dim cnt As Telerik.Cms.Engine.IContent = Telerik.Cms.Engine.ContentManager.Providers(provider).GetContent(id)
                    If cnt IsNot Nothing Then
                        urlResolved = cnt.UrlWithExtension
                    End If
                End If
            End If
            If String.IsNullOrEmpty(urlResolved) Then
                Return [String].Concat("Item not found: " + unresolvedUrl)
                If urlResolved.StartsWith("~/") Then
                    urlResolved = VirtualPathUtility.ToAbsolute(urlResolved)
                End If
                Return urlResolved
            End If
        End Function

2 posts, 0 answered