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

Forums / Developing with Sitefinity / Fetch and Display Content Item

Fetch and Display Content Item

2 posts, 0 answered
  1. Martin
    Martin avatar
    5 posts
    Registered:
    19 Dec 2007
    06 Jun 2011
    Link to this post
    Hi

    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)

    Regards

    Martin

                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
                    Next
                End If

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

    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...
    http://www.sitefinity.com/devnet/forums/sitefinity-3-x/developing-with-sitefinity/rendering-images-from-libraries-in-list-item-programmatically.aspx

    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()
            sbResolved.Append(strContent)
     
            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)
            Loop
     
            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)
            Else
                If urlResolved.StartsWith("~/") Then
                    urlResolved = VirtualPathUtility.ToAbsolute(urlResolved)
                End If
                Return urlResolved
            End If
        End Function

    Martin
2 posts, 0 answered