More in this section

Forums / Developing with Sitefinity / How to display Thumbnails

How to display Thumbnails

4 posts, 1 answered
  1. Steven Lancaster
    Steven Lancaster avatar
    82 posts
    Registered:
    06 Nov 2009
    24 Mar 2010
    Link to this post
    Withe each Blog Post we have a Reporter and a Picture associated with it. When They get to the Full Story I am not sure how to display the Thumbnail associated with the Post. Here are the 2 pages associated with the problem. I can see the reporters Picture, but need the thumbnail associated with the content.

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using Telerik.News.WebControls;
    using Telerik.Cms.Web;
    using Telerik.Cms.Engine;
    using Telerik.Cms.Engine.ContentViewFiltering;
    using System.Collections;
    using Telerik.Blogs;
    using DeepBlueCore;
      
      
    public partial class Sitefinity_ControlTemplates_Blogs_ContentViewSingleItem : System.Web.UI.UserControl
    {
      
        #region Private contstraints
        private Guid[] selectedBlogs = new Guid[] { };
        private BlogManager blogManager;
        #endregion 
      
        protected void Page_Load(object sender, EventArgs e)
        {
            CommentDetail();
        }
      
        #region[Comments]
        private void CommentDetail()
        {
            #region[old]
            //Telerik.Blogs.BlogManager manager = new Telerik.Blogs.BlogManager("Blogs");
            //IList listOfAllBlogs = manager.GetBlogs();
            //Guid selectedPostGuid = new Guid();
            //string commentCount = "";
      
            //foreach (IBlog blogItem in listOfAllBlogs)
            //{
            //    Guid parentId = blogItem.ID;
            //    IList allposts = manager.GetPosts(string.Empty, parentId, parentId);
      
            //    if (Common.QueryString("sessionid").Length > 0)
            //    {
            //        selectedPostGuid = new Guid(Common.QueryString("sessionid"));
      
            //        foreach (IContent post in allposts)
            //        {
            //            if (post.ID == selectedPostGuid)
            //            {
            //                hplComment.NavigateUrl = string.Format("~/BlogComment/{0}", post.UrlWithExtension);
      
            //                break;
            //            }
            //        }
            //    }
            //    else
            //    {
            //        if (Session["sessIContentGuid"] != null)
            //        {
            //            selectedPostGuid = new Guid(Session["sessIContentGuid"].ToString());
      
            //            foreach (IContent post in allposts)
            //            {
            //                if (post.ID == selectedPostGuid)
            //                {
            //                    hplComment.NavigateUrl = string.Format("~/BlogComment/{0}", post.UrlWithExtension);
            //                    GetReporterInfo((string)post.GetMetaData("Reporter"));
            //                    break;
            //                }
            //            }
            //        }
            //    }
            //}
            #endregion
      
            Telerik.Blogs.BlogManager manager = new Telerik.Blogs.BlogManager("Blogs");
            IList listOfAllBlogs = manager.GetBlogs();
            Guid selectedPostGuid = new Guid();
            string commentCount = "";
      
            foreach (IBlog blogItem in listOfAllBlogs)
            {
                Guid parentId = blogItem.ID;
                IList allposts = manager.GetPosts(string.Empty, parentId, parentId);
      
                if (Common.QueryString("searchid").Length > 0)
                {
                    selectedPostGuid = new Guid(Common.QueryString("searchid"));
      
                    foreach (IContent post in allposts)
                    {
                        if (post.ID == selectedPostGuid)
                        {
                            if (!string.IsNullOrEmpty((string)post.GetMetaData("Reporter")))
                            {
                                GetReporterInfo((string)post.GetMetaData("Reporter"));
                                break;
                            }
                            else
                                sfReporterPhoto.Visible = false;
                        }
                    }
                }
                else
                {
                    if (Session["sessIContentGuid"] != null)
                    {
                        selectedPostGuid = new Guid(Session["sessIContentGuid"].ToString());
      
                        foreach (IContent post in allposts)
                        {
                            if (post.ID == selectedPostGuid)
                            {
                                if (!string.IsNullOrEmpty((string)post.GetMetaData("Reporter")))
                                {
                                    GetReporterInfo((string)post.GetMetaData("Reporter"));
                                    break;
                                }
                                else
                                    sfReporterPhoto.Visible = false;
                            }
                        }
                    }
                }
            }
        }
        #endregion
      
        #region[Reporter Info]
        private void GetReporterInfo(string contentID)
        {
            if (contentID.Length > 0)
            {
                Guid contentGuid = new Guid(contentID);
      
                // create new instance of ContentManager
                Telerik.Cms.Engine.ContentManager contentManager = new Telerik.Cms.Engine.ContentManager();
      
                // get all content items
                IList listOfContentItems = contentManager.GetContent();
                if (listOfContentItems.Count > 0)
                {
                    foreach (IContent iContent in listOfContentItems)
                    {
                        if (iContent.ID == contentGuid)
                        {
                            string reporterPhoto = (string)iContent.GetMetaData("ReporterPhoto");
                            lAuthorName.Text = (string)iContent.GetMetaData("Name");
                            lAuthorName2.Text = (string)iContent.GetMetaData("Name");
                            hpAuthorBioURL.NavigateUrl = string.Format("~/Reporters.aspx?rpt={0}",iContent.ID.ToString());
                            hpAuthorBioURL.Text = "READ BIOGRAPHY";
                            ReporterCaption.Text = (string)iContent.GetMetaData("ReporterCaption");
                            ReporterCaption2.Text = (string)iContent.GetMetaData("ReporterCaption");
      
                            if (reporterPhoto.Length > 0)
                                sfReporterPhoto.ImageUrl = string.Format("{0}", reporterPhoto);
                            else
                                sfReporterPhoto.Visible = false;
      
                            break;
      
      
                               
      
                        }
                    }
                }
            }
            //string PrintID = "";
            if (Session["content.ID"] != null)
            {
                Label PrintID = (Label)Session["content.ID"];
            }
      
        }
        #endregion
      
        public Guid[] SelectedBlogs
        {
            get
            {
                return this.selectedBlogs;
            }
            set
            {
                this.selectedBlogs = value;
            }
        }  
      
      
          
    }



    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="ContentViewSingleItem.ascx.cs" Inherits="Sitefinity_ControlTemplates_Blogs_ContentViewSingleItem" %>
    <%@ Register Assembly="Telerik.Cms.Engine" Namespace="Telerik.Cms.Engine.WebControls" TagPrefix="sfWeb" %>
    <%@ Register Assembly="Telerik.Cms.Web.UI" Namespace="Telerik.Web.UI.SpamProtection" TagPrefix="sfWeb" %>
    <%@ Register Assembly="Telerik.Cms.Web.UI" Namespace="Telerik.Cms.Web.UI" TagPrefix="sfWeb" %>
    <%@ Register Assembly="Telerik.Blogs" Namespace="Telerik.Blogs.WebControls" TagPrefix="sfWeb" %>
    <%@ Register TagPrefix="sf" Assembly="Telerik.Cms.Engine" Namespace="Telerik.Cms.Engine.WebControls" %>
    <%@ Register TagPrefix="TN" TagName="ucPostAnonomously" Src="~/Sitefinity/ControlTemplates/Blogs/ucPostAnonomously.ascx" %>
    <%@ Register TagPrefix="TN" TagName="ucSendFriend" Src="~/Sitefinity/ControlTemplates/Blogs/ucSendFriend.ascx" %>
      
    <telerik:CssFileLink ID="CssFileLink1" EmbeddedFileName="Telerik.Blogs.Resources.ControlTemplates.Frontend.blogsCommonLayout.css" FileName="" Media="screen" runat="server" />
    <telerik:JsFileLink id="jsLink" runat="server" ScriptType="jQuery" /> 
      
    <script runat="server">
        void Button1_Click(object sender, EventArgs e)
        {       
            Session["PostID"] = content.ID;
            Response.Redirect("~/printFriendly.aspx");
              
        }
      
    </script>
      
    <asp:PlaceHolder ID="trackbackScript" runat="server">
    </asp:PlaceHolder>
      
    <div class="sf_singlePost">
    <asp:Label ID="AuthorPhoto" runat="server" Visible="false"></asp:Label>
        <asp:Label ID="AuthorName" runat="server" Visible="false"></asp:Label>
        <asp:Label ID="AuthorBioURL" runat="server" Visible="false"></asp:Label>
            <%-- %><asp:Button ID="Button1" runat="server" Text="Printer Friendly" OnClick="Button1_Click" />--%>
                <%--<a href="<%#string.Format("~/Comments/{0}.aspx?searchid={1}#comments", Eval("URL"))%>">TEST</a> --%>
        <%--<p class="sf_back">
           <asp:HyperLink ID="backToList1" Text="<%$Resources:GoBack %>" runat="server"> I WANT THUMBNAIL HERE</asp:HyperLink
        </p>--%>
      
       <h1 class="sf_postTitle">
            <asp:Literal ID="Title" runat="server"></asp:Literal>
        </h1>
         <!-- post author :begin-->
        <div class="post-author">
            <span class="a-img-bg"><sfWeb:SitefinityImage  ID="sfReporterPhoto" runat="server" Width="176px" Height="199px"  /></span><span class="a-name"><asp:Literal ID="lAuthorName" runat="server"></asp:Literal></span>
            <p class="a-desc"><asp:Literal ID="ReporterCaption" runat="server"></asp:Literal></p>
            <asp:HyperLink ID="hpAuthorBioURL" runat="server" ></asp:HyperLink>
         </div>
        <!-- post author :end-->
          
       <p class="sf_postAuthor">
            <%--<asp:Literal ID="Literal3" runat="server" Text="<%$Resources:Author %>"></asp:Literal>
            <asp:HyperLink ID="postedBy" runat="server">
                <asp:Literal ID="Author" runat="server"></asp:Literal>
            </asp:HyperLink>--%>
            Written By: <asp:Literal ID="lAuthorName2" runat="server"></asp:Literal>
        </p>
       <p class="sf_postAuthor">
                                   
                <asp:Literal ID="ReporterCaption2" runat="server"></asp:Literal>
        </p>
        <p class="sf_postDate">
            <telerik:DateTimeLiteral runat="server" ID="Publication_Date" DateFormatString="D"></telerik:DateTimeLiteral>
        </p>
        <asp:Panel ID="pnlContent" runat="server" CssClass="sf_postContent">
            <asp:Literal ID="content" runat="server"></asp:Literal>
        </asp:Panel>
         <%--<p class="sf_postCategory">
            <asp:Literal ID="CategoryLiteral" runat="server" Text="<%$Resources:Category %>" />: <asp:HyperLink ID="Category" runat="server" />
         </p>--%>
         <p class="sf_postTags">
              
            <asp:Repeater ID="Tags" runat="server">
                <HeaderTemplate>
                    <asp:Literal ID="TagsLiteral" runat="server" Text="<%$Resources:Tags %>" />
                </HeaderTemplate>
                <ItemTemplate>
                    <asp:HyperLink ID="tagLink" runat="server" />
                </ItemTemplate>
            </asp:Repeater>
        </p>
          
        <asp:Repeater ID="Bookmarks" runat="server">
            <HeaderTemplate><ul class="sf_socialBookmarks"></HeaderTemplate>
            <ItemTemplate>
                <li>
                    <asp:HyperLink ID="BookmarkLink" runat="server">
                        <asp:Image ID="BookmarkImage" runat="server" />
                    </asp:HyperLink>
                </li>
            </ItemTemplate>  
            <FooterTemplate></ul></FooterTemplate>
        </asp:Repeater>  
          
    </div>
      
      
    <div class="">
        <sfWeb:BlogCommentsList ID="commentsList" runat="server" CssClass="sf_commentsList" ValidationGroup="commentInfo">
                  <LayoutTemplate>
            <asp:Repeater ID="commentsRepeater" runat="Server" >
              
        <HeaderTemplate>
            <asp:PlaceHolder runat="server" ID="headerHolder" Visible="true">
                <h2 class="sf_comments" style="padding-left:15px;">
                    <asp:Literal ID="Literal1" runat="server" Text="<%$Resources:Comments %>" />
                    (<asp:Literal ID="commentsCount" runat="server"></asp:Literal>)
                </h2
            </asp:PlaceHolder>      
            <div class="sf_dbComment">
            <ul class="sf_commentListing">
        </HeaderTemplate>
        <ItemTemplate
            <!-- comment goes here -->
            <sfWeb:CommentItem Id="anonCommentContainer" runat="server" CssClass="sf_anonymousComment"
              
             <Template>
                  
                    <div class="sfComment1Top"></div>
                    <div class="sfComment1Body">
                        <asp:Label ID="text" runat="server"></asp:Label>
                    </div>
                    <div class="sfComment1Bot"></div>           
                 
                   <p class="sf_commentAuthor" style="padding-left:20px;">
                        <strong style="color:#d81b1a">
                            <asp:HyperLink ID="webSiteLink" runat="server" Visible="false" rel="nofollow"></asp:HyperLink>
                            <asp:Literal runat="Server" ID="authorName"  Visible="false"></asp:Literal
                        </strong>
                        <%--<abbr class="date" id="commentDate" runat="server" > </abbr>--%>
                        <telerik:DateTimeLiteral ID="commentDateLiteral" runat="server" DateFormatString="f" />
                    </p>
                  
            </Template>
             
            </sfWeb:CommentItem>
             
            <sfWeb:CommentItem Id="authorCommentContainer" runat="server"  CssClass=""
             <Template>
                <div class="sfComment2Top"></div>
                <div class="sfComment2Body">
                    <asp:Label ID="text" runat="server"></asp:Label>
                </div>
                <div class="sfComment2Bot"></div>
                      
                 <p class="sf_commentAuthor" style="padding-left:20px;">
                    <strong style="color:#d81b1a">
                        <asp:HyperLink ID="webSiteLink" runat="server" Visible="false" rel="nofollow"></asp:HyperLink>
                        <asp:Literal runat="Server" ID="authorName"  Visible="false" ></asp:Literal
                    </strong>
                    <%--<abbr class="date" id="commentDate" runat="server"> </abbr>--%>
                    <telerik:DateTimeLiteral ID="commentDateLiteral" runat="server" DateFormatString="f" />
                </p>
                  
             </Template>
              
           </sfWeb:CommentItem>
              
        </ItemTemplate>
        <FooterTemplate>
            </ul>
            </div>
        </FooterTemplate>
    </asp:Repeater>
    <asp:PlaceHolder ID="moderationHolder" runat="server" Visible="false">
        <p class="sf_commentMessage">
            <asp:Literal ID="Literal2" runat="server" Text="<%$Resources:CommentMessageModeration %>"></asp:Literal>
        </p>
    </asp:PlaceHolder>
      
        <div class="sf_PostCommentHeader"></div>
        <fieldset class="sf_postNewComment">
              
            <ol>
                <li>
                    <asp:Label ID="Label2" runat="Server" Text="<%$Resources:Name %>" AssociatedControlID="authorTxt"></asp:Label>
                    <asp:TextBox ID="authorTxt" runat="server" size="30"></asp:TextBox>
                    <asp:RequiredFieldValidator runat="server" ID="authorVal" ControlToValidate="authorTxt"
                            ErrorMessage="<%$Resources:NameEmpty %>" Display="dynamic" 
                            CssClass="sf_commentsValidator"></asp:RequiredFieldValidator>
      
                </li>
                <li>
                    <asp:Label ID="Label3" runat="Server" Text="<%$Resources:Email %>" AssociatedControlID="emailTxt"></asp:Label>
                    <asp:TextBox ID="emailTxt" runat="server" size="30"></asp:TextBox>
                    <asp:RegularExpressionValidator runat="server" ID="emailVal" ControlToValidate="emailTxt"
                            ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ErrorMessage="<%$Resources:InvalidEmail %>"
                            Display="dynamic" CssClass="sf_commentsValidator"></asp:RegularExpressionValidator>
                </li>
                <li>
                    <asp:Label ID="Label4" runat="Server" Text="<%$Resources:WebSite %>" AssociatedControlID="webSiteTxt"></asp:Label>
                    <asp:TextBox ID="webSiteTxt" runat="server" size="30"></asp:TextBox
                </li>
                <li class="texarea-wrapper">
                    <asp:Label ID="Label1" runat="Server" Text="<%$Resources:Comment %>" AssociatedControlID="commentTxt"></asp:Label>
                    <div>
                        <a href="#" class="formattingOptionsToggleBtn" onclick='if($(this).parent().hasClass("formattingOptions")){$(this).parent().removeClass("formattingOptions");$(this).text("Formatting options");}else{$(this).parent().addClass("formattingOptions");$(this).text("Hide formatting options"); } return false;'>Formatting options</a>
                         <telerik:RadEditor 
                                runat="server" 
                                ID="commentTxt"
                                ToolsFile="~/Sitefinity/ControlTemplates/Blogs/ToolsFile.xml"
                                EnableEmbeddedSkins="True" 
                                Skin="Default" 
                                Width="99%"
                                Height="200px" 
                                EditModes="Design">            
                         </telerik:RadEditor>   
                    </div>  
                     <asp:RequiredFieldValidator runat="server" ID="contentVal" 
                            ControlToValidate="commentTxt"
                            ErrorMessage="<%$Resources:CommentEmpty %>" 
                            Display="dynamic" 
                            ValidationGroup="commentInfo"
                            CssClass="sf_commentsValidator">
                            <strong>Message text is required</strong>
                     </asp:RequiredFieldValidator>                                                                                                                    
                </li>           
                <li>
                <sfWeb:SpamProtector id="spamProtector" runat="server" cssclass="commentsValidator hide"
                    enableautobotdiscovery="true" enablehiddentextboxstrategy="true"
                    hiddentextboxerrormessage="Hidden TextBox has some text in it!" hiddentextboxlabel="Do not fill this textbox!"
                    hiddentextboxlabelcssclass="hide" hiddentextboxinputcssclass="hide" enablemintimeoutstrategy="true"
                    mintimeout="2" mintimeouterrormessage="Submission too fast!" />
                <asp:Button ID="submitBtn" runat="server" Text=""
                    CssClass="sf_commentSubmit" />
                </li>
            </ol>
        </fieldset>
      
            </LayoutTemplate>
        </sfWeb:BlogCommentsList>
    </div>
    <br />
      
    <div class="sf_dbComment">    
        <TN:ucPostAnonomously id="ucPostAnonomously1" runat="server" />
        <TN:ucSendFriend id="ucSendFriend1" runat="server" />
    </div>
      
    <div class="sf_dbComment" visible="false" runat="server">
        <asp:HyperLink cssclass="post-a-comment" ID="hplComment" runat="server"></asp:HyperLink>   
    </div>
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    25 Mar 2010
    Link to this post
    Hi Steven Lancaster,

    Create a hidden metafield for Blogs that will be set when a new post is created or updated. The value of this metakey should be associated with a profile property - by default each user can have Photo.

    sample

    var profiler = ProfileBase.Create(UserManager.GetCurrentUserName());
    var obj = profiler.GetPropertyValue("Photo");
    // here set the Photo Value to your hidden metakey
    cntItem.SetMetaData("AuthorImage", obj);

    Then for each post call GetMetaData method of IContent item and display the image.

    All the best,
    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. Steven Lancaster
    Steven Lancaster avatar
    82 posts
    Registered:
    06 Nov 2009
    25 Mar 2010
    Link to this post
    Ok let me explain we already have the field see picture. Since I did not create this webiste. How using the code that I posted earlier do I pull this Thumbnail image and display it.

    Sorry if I was unclear.

    Thank you in advance for any help.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    25 Mar 2010
    Link to this post
    Hi Steven Lancaster,

    Then for each post call GetMetaData method of IContent item and display the image. You can take a look at IContent methods.

    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.
    Answered
Register for webinar
4 posts, 1 answered