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

Forums / General Discussions / Custom Module

Custom Module

54 posts, 0 answered
  1. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    29 Nov 2010
    Link to this post
    Hello Asif,

    You have to add the following code to the problematic template

    <divclass="groupEdit">
     
        <asp:LinkButtonID="groupOperationsLink"runat="server"CssClass="groupEditExpand"OnClientClick="groupOpsVisible = ToggleDiv('groupOperationsDiv'); return false;">
     
            <asp:LiteralID="litButton1"runat="server"Text="GroupOperations"></asp:Literal>
     
        </asp:LinkButton>
     
        <divid="groupOperationsDiv"style="display: none; ">
     
            <divclass="groupActionsPopup">
     
                <spanclass="numberOfSelectedItem"><strongid="numberOfSelectedItems">0</strong><asp:LiteralID="lblSelectedItems"runat="server"Text="ItemsSelected"></asp:Literal></span>
     
                <ul>
     
                    <li>
     
                        <spanid="disabledDeleteGroupGrid"class="disabled"><asp:LiteralID="Literal20"runat="server"Text="Delete"></asp:Literal></span>
     
                        <asp:LinkButtonStyle="display: none;"ID="btnDeleteGroupGrid"runat="server"OnClientClick="DeleteWithConfirmation(); return false;"Text="Delete"></asp:LinkButton>
     
                        <asp:LiteralID="lblSelected"runat="server"Text="<%$Resources:Selected %>" />
     
                    </li>
     
                </ul>
     
            </div>
     
        </div>
     
    </div>

    You can download external templates archive and merge ProductItemsList.ascx with ContentItemsList.ascx.


    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
  2. Asif
    Asif avatar
    110 posts
    Registered:
    18 Nov 2010
    30 Nov 2010
    Link to this post

    After inserting the code in the file productItemsList.ascx. I am getting following error If I logged in with non admin user and click on my custom module.

    Object reference not set to an instance of an object.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

  3. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    30 Nov 2010
    Link to this post
    Hello Asif,

    Can you provide the stack trace of the error.

    Best wishes,
    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
  4. Asif
    Asif avatar
    110 posts
    Registered:
    18 Nov 2010
    01 Dec 2010
    Link to this post
    Hi,
    When I create a product using custom module and after creating a product if I click on "edit" link then I get this error.

    A required control was not found in the template for "~/Sitefinity/Admin/ControlTemplates/Generic_Content/GenericContentDesigner.ascx". The control must be assignable form type "System.Web.UI.Control" and must have ID "Name".


    Stack Trace
    [TemplateException: A required control was not found in the template for "~/Sitefinity/Admin/ControlTemplates/Generic_Content/GenericContentDesigner.ascx". The control must be assignable form type "System.Web.UI.Control" and must have ID "Name".]
       Telerik.Cms.Web.UI.GenericContainer.ThrowException(Type requiredType, String controlId) +58
       Telerik.Cms.Web.UI.GenericContainer.GetControl(String id, Boolean required) +173
       Telerik.Cms.Engine.WebControls.Admin.ContentItemEdit`1.get_ContentName() +66
       Telerik.Cms.Engine.WebControls.Admin.ContentItemEdit`1.SetContentForm(IContent cnt) +344
       Telerik.Cms.Engine.WebControls.Admin.ContentItemEdit`1.InitializeControls(Control viewContainer) +32
       Telerik.Cms.Web.UI.ViewModeControl`1.CreateChildControls() +101
       System.Web.UI.Control.EnsureChildControls() +87
       System.Web.UI.Control.PreRenderRecursiveInternal() +44
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842
    
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    01 Dec 2010
    Link to this post
    Hello Asif,

    Inside this template - GenericContentDesigner.ascx you should have a control with ID="Name".  the stack shows that you are trying to make some content edit through ContentItemEdit base view.

    Sincerely yours,
    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
  6. Asif
    Asif avatar
    110 posts
    Registered:
    18 Nov 2010
    02 Dec 2010
    Link to this post
    Hi,
    I want to add permalink in one of my blog. So, how to do that? I am using an external template for it and all items are in repeater. So, is there any easiest way to add permalink?
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    03 Dec 2010
    Link to this post
    Hello Asif,

    You can set permalink to a post. The actual blog is not displayed. BlogPosts control displays posts from your blogs.

    <asp:HyperLink ID="fullContent2" runat="server">
          <asp:Literal ID="Title" runat="server" />
    </asp:HyperLink>

    When the ID of the HyperLink is fullContent + i where i < 6 the NavigateUrl property will be automatically set.

    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
  8. Asif
    Asif avatar
    110 posts
    Registered:
    18 Nov 2010
    03 Dec 2010
    Link to this post
    After inserting the code in the file productItemsList.ascx. I am getting following error If I logged in with non admin user and click on my custom module.

    Object reference not set to an instance of an object.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [NullReferenceException: Object reference not set to an instance of an object.]
       Telerik.Cms.Engine.WebControls.Admin.ContentItemsList`1.InitializeControls(Control viewContainer) +173
       Telerik.Cms.Web.UI.ViewModeControl`1.CreateChildControls() +101
       System.Web.UI.Control.EnsureChildControls() +87
       System.Web.UI.Control.PreRenderRecursiveInternal() +44
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842
    


  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    03 Dec 2010
    Link to this post
    Hello Asif,

    The error does not provide some detailed information about which object is null. Can you attach the module you have created or show the view that you use and inherits from ContentItemsList and its template.

    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
  10. Asif
    Asif avatar
    110 posts
    Registered:
    18 Nov 2010
    03 Dec 2010
    Link to this post
    Hi,
    I am facing issue when i create a new user and click on my new module after logged in with the new user then I get the exception. I can't attach my entire module as it is 23 Mb file. You want only library? or you want the screen shots of my code? Can you specify the pages name I can provide you the screen shot of them?
    please help
  11. Asif
    Asif avatar
    110 posts
    Registered:
    18 Nov 2010
    03 Dec 2010
    Link to this post
    Hi,
    Please find the attached pdf. I want to create a Add FAQ page using the custom module. I have done pretty much things so far but 2 areas are left.
    (I have marked the sections with red Question mark)
    1. Links to Related Videos:
    2. Links to Related FAQs:
    Is there any code I can use to build these sections?
  12. Asif
    Asif avatar
    110 posts
    Registered:
    18 Nov 2010
    04 Dec 2010
    Link to this post
    One more thing. I am using the code "Archive.ascx" / ".cs" and "BlogCategory.ascx" / "cs" pages to show blog categories and blogs archives by dates. I want to use this for News, Events and Forums. Is there any code I can use for them as well?
  13. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    05 Dec 2010
    Link to this post
    Hi Asif,

    For your FAQ and Videos section you have to create a custom PropertyEditorDialogs.

    Could you explain some more about "I am using the code "Archive.ascx" / ".cs" and "BlogCategory.ascx" / "cs" . Are these files some custom views you have created?

    Greetings,
    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
  14. Asif
    Asif avatar
    110 posts
    Registered:
    18 Nov 2010
    05 Dec 2010
    Link to this post
    Hi, Actually I want to show the two lists which display name and count of news category and other list to display news dates (months and year) and if any customer clicks on it then it shows the description. If there is any code or user control I can use for it also I want to use same functionality for forum as well
  15. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    06 Dec 2010
    Link to this post
    Hello Asif,

    We do not have such a control out of the box

    1. To show categories and count

    privateintGetCachedCategoryCount(ICategory category)
     {
         objectcontentCount = 0;
         stringkey = Manager.GenerateCategoryCountCacheKey(category.CategoryName);
         if(Context != null)
         {
             // use caching - if there are many categories - over 200 you might experience some issue. If you do not plan to have many categories - remove the caching
             contentCount = Context.Cache[key];
             if(contentCount == null)
             {
                 contentCount = GetCategoryCount(category);
                 Context.Cache.Add(key, contentCount, null, DateTime.Now.AddDays(1d), Cache.NoSlidingExpiration,
                                   CacheItemPriority.Normal, null);
             }
         }
         return(int)contentCount;
     }
      
      privateintGetCategoryCount(ICategory category)
      {
                IList categoriesTree = Manager.GetCategoriesTree(category);
                List<IMetaSearchInfo> filter = newList<IMetaSearchInfo>();
                foreach(ICategory categoryItem incategoriesTree)
                    filter.Add(newMetaSearchInfo(MetaValueTypes.ShortText, "CustomCategory", categoryItem.CategoryName, SearchCondition.Equal, JoinType.And));
      
                intcontentCount = Manager.GetContent(filter.ToArray()).Count;
                returncontentCount;
      }

    2. To get the dates you can use filter expression (IMetaSearchInfo)

    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
  16. Asif
    Asif avatar
    110 posts
    Registered:
    18 Nov 2010
    06 Dec 2010
    Link to this post
    Hi,
    Thanks a lot for your help. You are awesome.
    Can you help me to fix this issue. I am using your code to show categories but not sure what reference or namspace i need for "Manager". If I write this code "Manager.GenerateCategoryCountCacheKey"
  17. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    06 Dec 2010
    Link to this post
    Hello Asif,

    You have to use Telerik.Cms.Engine.ContentManager

    ContentManager Manager = new ContentManager();

    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
  18. Asif
    Asif avatar
    110 posts
    Registered:
    18 Nov 2010
    06 Dec 2010
    Link to this post
    Hi,
    I am suing this cs code for showing categories in Blog and its count and this code is working really fine. Can I make change on this code and make it use full for News and Forums?

    /*  CS code */

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Data;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.ComponentModel;
    using Telerik.Cms.Engine;
    using Telerik.Blogs;
    using Telerik.Cms;
    using Telerik.Framework.Web.Design;
    using Telerik.Cms.Web.UI;
    using Telerik.Rss;

    public partial class UserControls_BlogCategory : System.Web.UI.UserControl, IPostList
    {
        #region Properties

        /// <summary>
        /// Array of blog ids from which posts should be displayed.
        /// </summary>
        [TypeConverter("Telerik.Blogs.WebControls.SelectedBlogsConverter, Telerik.Blogs")]
        [WebEditor("Telerik.Blogs.WebControls.BlogsSelector, Telerik.Blogs")]
        public Guid[] SelectedBlogs
        {
            get
            {
                return this.selectedBlogs;
            }
            set
            {
                this.selectedBlogs = value;
            }
        }

        /// <summary>
        /// Provider name property is dependent propery needed by Telerik.Blogs.WebControls.BlogSelector
        /// web editor
        /// </summary>
        [Category("Data")]
        public string ProviderName
        {
            get
            {
                return this.providerName;
            }
            set
            {
                this.providerName = value;
            }
        }

        /// <summary>
        /// Url of the page where ArchivePostList control resides
        /// </summary>
        [WebEditor("Telerik.Cms.Web.UI.UrlEditorWrapper, Telerik.Cms")]
        public virtual string BlogPageUrl
        {
            get
            {
                object obj = this.ViewState["BlogPageUrl"];
                if (obj != null)
                    return (string)obj;
                if (Telerik.Cms.Web.CmsUrlContext.Current != null)
                {
                    string pageRelative = Telerik.Cms.Web.CmsUrlContext.Current.Path;
                    pageRelative = pageRelative.Replace(Telerik.Cms.Web.UrlHelper.LowerApplicationPath, "");
                    if (pageRelative.EndsWith(Telerik.Cms.Web.UrlHelper.PageExtension))
                        return String.Concat("~/", pageRelative);
                    else
                        return String.Concat("~/", pageRelative, Telerik.Cms.Web.UrlHelper.PageExtension);
                }
                return String.Empty;
            }
            set
            {
                this.ViewState["BlogPageUrl"] = value;
            }
        }

        #endregion

        #region Methods

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack && SelectedBlogs != null)
            {
                IList listOfCategories = GetCategoryPosts();
                rptCategories.DataSource = listOfCategories;
                rptCategories.DataBind();            
            }
        }

        protected void rptCategories_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Telerik.Cms.Engine.ContentManager contentManager = new ContentManager("Blogs");
                Literal litLink = (Literal)e.Item.FindControl("litLink");
                ICategory category = ((Telerik.Cms.Engine.ICategory)e.Item.DataItem);
                int catItems = CountPosts(category);
                if (catItems > 0)
                {
                    litLink.Text = "<a href=\"" + ResolveUrl(BlogPageUrl) + "?BlogCatID=" + category.ID.ToString() + "\">" + category.CategoryName + "</a> (" + catItems + ")";
                }
                else
                {
                    e.Item.Visible = false;
                }
            }
        }
        
        private IList GetCategoryPosts()
        {
            BlogManager manager = new BlogManager();
            IList posts = manager.GetPosts("", SelectedBlogs);

            List<ICategory> results = new List<ICategory>();
            
            foreach (IContent post in posts)
            {
                string catName = post.GetMetaData("Category").ToString();
                if (catName == null || catName == string.Empty)
                    continue;

                Telerik.Cms.Engine.ICategory getCategoryForPRovider = (ICategory)manager.Content.GetCategory(catName);
                if (results.IndexOf(getCategoryForPRovider) < 0)
                {
                    results.Add(getCategoryForPRovider);
                }
            }

            return results;
        }

        private int CountPosts(ICategory category)
        {
            BlogManager manager = new BlogManager();
            IList posts = manager.GetPosts("", SelectedBlogs);
            int numPosts = 0;

            foreach (IContent post in posts)
            {
                string catName = post.GetMetaData("Category").ToString();
                if (catName != null && catName != string.Empty && catName == category.CategoryName)
                {
                    numPosts++;
                }
            }

            return numPosts;
        }

        #endregion

        #region Private fields

        private Guid[] selectedBlogs;
        private string providerName;

        #endregion
    }

    /* ascx code */

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="BlogCategory.ascx.cs" Inherits="UserControls_BlogCategory" %>

    <div class="sf_column-title">
                <span>Blogs By Category</span> <a class="triggers"></a>
            </div>
    <asp:Repeater ID="rptCategories" runat="server" OnItemDataBound="rptCategories_ItemDataBound">
        <HeaderTemplate><ul></HeaderTemplate>
        <ItemTemplate>
            <li><asp:Literal ID="litLink" runat="server"></asp:Literal></li>
        </ItemTemplate>
        <FooterTemplate></ul></FooterTemplate>
    </asp:Repeater>
    <span class="divider"></span>
  19. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    06 Dec 2010
    Link to this post
    Hello Asif,

    You can easily make it working for News by setting News as a provider of  ContentManager("News"). For forums you should use the specific API.

    Greetings,
    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
  20. Asif
    Asif avatar
    110 posts
    Registered:
    18 Nov 2010
    06 Dec 2010
    Link to this post
    Hi,
    These 2 methods I am using for Blogs.
    Can you show me how to make changes in it to make it work for News?

    private IList GetCategoryPosts()
        {
            BlogManager manager = new BlogManager();
            IList posts = manager.GetPosts("", SelectedBlogs);

            List<ICategory> results = new List<ICategory>();
            
            foreach (IContent post in posts)
            {
                string catName = post.GetMetaData("Category").ToString();
                if (catName == null || catName == string.Empty)
                    continue;

                Telerik.Cms.Engine.ICategory getCategoryForPRovider = (ICategory)manager.Content.GetCategory(catName);
                if (results.IndexOf(getCategoryForPRovider) < 0)
                {
                    results.Add(getCategoryForPRovider);
                }
            }

            return results;
        }

        private int CountPosts(ICategory category)
        {
            BlogManager manager = new BlogManager();
            IList posts = manager.GetPosts("", SelectedBlogs);
            int numPosts = 0;

            foreach (IContent post in posts)
            {
                string catName = post.GetMetaData("Category").ToString();
                if (catName != null && catName != string.Empty && catName == category.CategoryName)
                {
                    numPosts++;
                }
            }

            return numPosts;
        }
  21. Asif
    Asif avatar
    110 posts
    Registered:
    18 Nov 2010
    06 Dec 2010
    Link to this post
    Hi,
    I am using below code for News Categories and I am getting an error

    Could not find a type for a name.  The type name was 'Telerik.News.WebControls.NewsSelector, Telerik.News'.

    Please find my code below

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Data;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.Caching;
    using System.ComponentModel;
    using Telerik.Cms.Engine;
    using Telerik.News;
    using Telerik.Cms;
    using Telerik.Framework.Web.Design;
    using Telerik.Cms.Web.UI;
    using Telerik.Rss;

    public partial class UserControls_NewsCategory : System.Web.UI.UserControl
    {
        #region Properties

        /// <summary>
        /// Array of blog ids from which posts should be displayed.
        /// </summary>
        [TypeConverter("Telerik.News.WebControls.SelectedNewsConverter, Telerik.News")]
        [WebEditor("Telerik.News.WebControls.NewsSelector, Telerik.News")]
        public Guid[] SelectedNews
        {
            get
            {
                return this.selectedNews;
            }
            set
            {
                this.selectedNews = value;
            }
        }

        /// <summary>
        /// Provider name property is dependent propery needed by Telerik.Blogs.WebControls.BlogSelector
        /// web editor
        /// </summary>
        [Category("Data")]
        public string ProviderName
        {
            get
            {
                return this.providerName;
            }
            set
            {
                this.providerName = value;
            }
        }

        /// <summary>
        /// Url of the page where ArchivePostList control resides
        /// </summary>
        [WebEditor("Telerik.Cms.Web.UI.UrlEditorWrapper, Telerik.Cms")]
        public virtual string NewsPageUrl
        {
            get
            {
                object obj = this.ViewState["NewsPageUrl"];
                if (obj != null)
                    return (string)obj;
                if (Telerik.Cms.Web.CmsUrlContext.Current != null)
                {
                    string pageRelative = Telerik.Cms.Web.CmsUrlContext.Current.Path;
                    pageRelative = pageRelative.Replace(Telerik.Cms.Web.UrlHelper.LowerApplicationPath, "");
                    if (pageRelative.EndsWith(Telerik.Cms.Web.UrlHelper.PageExtension))
                        return String.Concat("~/", pageRelative);
                    else
                        return String.Concat("~/", pageRelative, Telerik.Cms.Web.UrlHelper.PageExtension);
                }
                return String.Empty;
            }
            set
            {
                this.ViewState["NewsPageUrl"] = value;
            }
        }

        #endregion

        #region Methods

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack && SelectedNews != null)
            {
                IList listOfCategories = GetCategoryPosts();
                rptCategories.DataSource = listOfCategories;
                rptCategories.DataBind();
            }
        }

        protected void rptCategories_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Telerik.Cms.Engine.ContentManager contentManager = new ContentManager("News");
                Literal litLink = (Literal)e.Item.FindControl("litLink");
                ICategory category = ((Telerik.Cms.Engine.ICategory)e.Item.DataItem);
                int catItems = CountPosts(category);
                if (catItems > 0)
                {
                    litLink.Text = "<a href=\"" + ResolveUrl(NewsPageUrl) + "?NewsCatID=" + category.ID.ToString() + "\">" + category.CategoryName + "</a> (" + catItems + ")";
                }
                else
                {
                    e.Item.Visible = false;
                }
            }
        }

        private IList GetCategoryPosts()
        {
            ContentManager Manager = new ContentManager("News");
            IList posts = Manager.GetCategories();
            
            List<ICategory> results = new List<ICategory>();

            foreach (IContent post in posts)
            {
                string catName = post.GetMetaData("Category").ToString();
                if (catName == null || catName == string.Empty)
                    continue;

                Telerik.Cms.Engine.ICategory getCategoryForPRovider = (ICategory)Manager.GetCategory(catName);
                if (results.IndexOf(getCategoryForPRovider) < 0)
                {
                    results.Add(getCategoryForPRovider);
                }
            }

            return results;
        }

        private int CountPosts(ICategory category)
        {
            ContentManager Manager = new ContentManager("News");
            IList posts = Manager.GetCategories();
            int numPosts = 0;

            foreach (IContent post in posts)
            {
                string catName = post.GetMetaData("Category").ToString();
                if (catName != null && catName != string.Empty && catName == category.CategoryName)
                {
                    numPosts++;
                }
            }

            return numPosts;
        }

        #endregion

        #region Private fields

        private Guid[] selectedNews;
        private string providerName;

        #endregion
    }
  22. Asif
    Asif avatar
    110 posts
    Registered:
    18 Nov 2010
    07 Dec 2010
    Link to this post
    Hi,
    I am using below code to get Forum Categories But getting this error.
    Unable to cast object of type 'Telerik.Forums.Data.Category' to type 'Telerik.Cms.Engine.ICategory'

    private IList GetCategoryPosts()
        {
            Telerik.Forums.ForumManager forumManager = new Telerik.Forums.ForumManager();
            IList listOfAllCategories = forumManager.GetCategories();
            List<ICategory> results = new List<ICategory>();
            foreach (Telerik.Forums.ICategory categ in listOfAllCategories)
            {
           
                Telerik.Cms.Engine.ICategory getCategoryForPRovider = (ICategory)forumManager.GetCategory(categ.ID); //.GetCategory(categ.Name);
                if (results.IndexOf(getCategoryForPRovider) < 0)
                {
                    results.Add(getCategoryForPRovider);
                }
                          
            }

            return results;
        }
  23. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    07 Dec 2010
    Link to this post
    Hello Asif,

    You have to use Telerik.Forums.ICategory not Telerik.Cms.Engine.ICategory.

    Greetings,
    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
  24. Asif
    Asif avatar
    110 posts
    Registered:
    18 Nov 2010
    07 Dec 2010
    Link to this post
    hi,
    I am using below code for Forums Categories. But the good thing is I am not getting any error but the bad thing is I am not getting any result.Can you help me?
    private IList GetCategoryPosts()
        {
            Telerik.Forums.ForumManager forumManager = new Telerik.Forums.ForumManager();

            IList listOfAllCategories = forumManager.GetCategories();

            List<ICategory> results = new List<ICategory>();

            foreach (Telerik.Forums.ICategory categ in listOfAllCategories)
            {
               
                Telerik.Forums.ICategory getCategoryForPRovider = (ICategory)forumManager.GetCategory(categ.ID); //.GetCategory(categ.Name);
                if (results.IndexOf(getCategoryForPRovider) < 0)
                {
                    results.Add(getCategoryForPRovider);
                }
                        
            }

            return results;
        }
Register for webinar
54 posts, 0 answered
1 2