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

Forums / Developing with Sitefinity / ForumProvider implementation problems

ForumProvider implementation problems

8 posts, 2 answered
  1. Klemen Slavič
    Klemen Slavič avatar
    30 posts
    Registered:
    24 Jul 2009
    24 Nov 2010
    Link to this post
    I'm having trouble finding documentation on the Forums API, so I've decided to post this question here.

    As far as I know, the public controls for forums don't contain any parameters for filtering forums by category. The only thing I've seen that I could use is a custom forum provider that would filter the results coming from the default provider.

    So far, I've come up with the following solution:

    01.public class UncategorizedForumProvider : DefaultProvider
    02.{
    03.    public UncategorizedForumProvider() : base() { }
    04. 
    05.    public override System.Collections.IList GetCategories()
    06.    {
    07.        return (from Category c in base.GetCategories() where String.IsNullOrEmpty(c.ID.ToString()) select c).ToList();
    08.    }
    09. 
    10.    public override System.Collections.IList GetCategories(string sortExpr)
    11.    {
    12.        return (from Category c in base.GetCategories(sortExpr) where String.IsNullOrEmpty(c.ID.ToString()) select c).ToList();
    13.    }
    14. 
    15.    public override System.Collections.IList GetForums(bool excludeHidden)
    16.    {
    17.        return (from Forum f in base.GetForums(excludeHidden) where String.IsNullOrEmpty(f.CategoryID.ToString()) select f).ToList();
    18.    }
    19. 
    20.    public override System.Collections.IList GetRecentForums(int start, int max)
    21.    {
    22.        return (from Forum f in base.GetRecentForums(start, max) where String.IsNullOrEmpty(f.CategoryID.ToString()) select f).ToList();
    23.    }
    24.}

    ...and the accompanying entry in web.config:

    <add name="Uncategorized" securityProviderName="" profileProviderName="Sitefinity" type="UncategorizedForumProvider, App_Code" connectionStringName="DefaultConnection" visible="true"/>

    All is fine until I try setting the Provider Name in the ForumList control from "Sitefinity" to "Uncategorized", at which point the page editor errors out:

    ----------------------------------------------------------------------------------

    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.Forums.WebControls.ForumList.get_IsEmpty() +13
       Telerik.Cms.Web.UI.ControlDesigner.RenderWithHost() +400
       Telerik.Cms.Web.UI.ControlDesigner.RenderControl() +642
       Telerik.Cms.Web.UI.ControlDesigner.CreateChildControls() +1603
       System.Web.UI.Control.EnsureChildControls() +181
       System.Web.UI.Control.PreRenderRecursiveInternal() +59
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4184
    


    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1              

    ----------------------------------------------------------------------------------

    Have I missed any overrides? Or is there a better way to show just a specific category of forums, controlled from the page editor?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    24 Nov 2010
    Link to this post
    Hi Klemen,

    I believe that this message occurs only in edit mode. There should not be a problem on the public side, right?
    I checked the code and find what the problem is.  I made the fix and the issue will be added to the next SP. If this is critical for you, please open a support request where I can attach a custom build.

    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
  3. Klemen Slavič
    Klemen Slavič avatar
    30 posts
    Registered:
    24 Jul 2009
    24 Nov 2010
    Link to this post
    I cannot set the provider name on the control and publish the page, since the whole page turns into an exception, I can't see the publish button and therefore cannot verify whether the change works on the front page or not.

    Given that this is a blocker issue for our site, can you provide the custom build so we can move forward?
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    24 Nov 2010
    Link to this post
    Hello Klemen,

    Ok, open a support request ( if you have not already done this) and I will attach a custom build that you can use.

    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
    Answered
  5. Klemen Slavič
    Klemen Slavič avatar
    30 posts
    Registered:
    24 Jul 2009
    25 Nov 2010
    Link to this post
    It works now, thank you.
  6. Klemen Slavič
    Klemen Slavič avatar
    30 posts
    Registered:
    24 Jul 2009
    25 Nov 2010
    Link to this post
    Okay, further clarification: the Uncategorized ForumProvider now works, but I'm having trouble filtering by category, namely with a specific CategoryID. The class is another ForumProvider named DynamicsForumProvider and includes the following code:

    01.public class DynamicsForumProvider : DefaultProvider
    02.{
    03.    public string CategoryId { get; set; }
    04. 
    05.    public DynamicsForumProvider() : base()
    06.    {
    07.        CategoryId = ConfigurationManager.AppSettings["DynamicsCategoryId"];
    08.    }
    09. 
    10.    public override System.Collections.IList GetCategories()
    11.    {
    12.        return (from Category c in base.GetCategories() where c.ID.ToString() == CategoryId select c).ToList();
    13.    }
    14. 
    15.    public override System.Collections.IList GetCategories(string sortExpr)
    16.    {
    17.        return (from Category c in base.GetCategories(sortExpr) where c.ID.ToString() == CategoryId select c).ToList();
    18.    }
    19. 
    20.    public override System.Collections.IList GetForums(bool excludeHidden)
    21.    {
    22.        return (from Forum f in base.GetForums(excludeHidden) where f.CategoryID.ToString() == CategoryId select f).ToList();
    23.    }
    24. 
    25.    public override System.Collections.IList GetRecentForums(int start, int max)
    26.    {
    27.        return (from Forum f in base.GetRecentForums(start, max) where f.CategoryID.ToString() == CategoryId select f).ToList();
    28.    }
    29. 
    30.     
    31. 
    32.}

    The code is pretty much identical to the Uncategorized forum provider, but changing the provider to Dynamic (as specified in the web.config file) shows just the forums from the Uncategorized category (null). I've verified that using the default provider (Sitefinity) shows all forums, as expected.
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    25 Nov 2010
    Link to this post
    Hello Klemen,

    There are several overloads that are called depending on the forum type you are using


    • public abstract IList GetForums(bool excludeHidden) - Overloaded. Gets all forums in all categories   
    • public abstract IList GetForums(Guid[] ids, bool excludeHidden);- Gets specific forums by IDs, exclude hidden forums
    • public abstract IList GetForums(ICategory category, bool excludeHidden); - Gets all forums in a category
    • public abstract IList GetForums(Guid categoryID, bool excludeHidden) - Overloaded. Gets all forums in a category
    •  public abstract IList GetForumsUncategorized(bool excludeHidden) - Gets all forums that have no assigned category
    I think that you have used an inappropriate overload. Actually you can add all abstract methods to your custom provider and put break points on them which will allow you to see the correct method that is called, then you can add your "filtering" logic.
    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
    Answered
  8. Klemen Slavič
    Klemen Slavič avatar
    30 posts
    Registered:
    24 Jul 2009
    26 Nov 2010
    Link to this post
    Hi,

    Thanks for the pointers, the methods I implemented seem to be sufficient, the problem was different casing for the GUID written in web.config for the AppSettings. Lowercasing the ID solved the problem, along with overriding the GetUncategorizedForums(int start, int max) method to return an empty list.

    The final implementation is:

    public class DynamicsForumProvider : DefaultProvider
    {
        public string CategoryId { get; set; }
     
        public DynamicsForumProvider() : base()
        {
            CategoryId = ConfigurationManager.AppSettings["DynamicsCategoryId"].ToLower();
        }
     
        public override System.Collections.IList GetCategories()
        {
            var ret = (from Category c in base.GetCategories() where c.ID.ToString() == CategoryId select c).ToList();
            return ret;
        }
     
        public override System.Collections.IList GetCategories(string sortExpr)
        {
            var cat = base.GetCategories(sortExpr);
            var ret = (from Category c in cat where c.ID.ToString() == CategoryId select c).ToList();
            return ret;
        }
     
        public override System.Collections.IList GetCategoriesByIds(params Guid[] ids)
        {
            var ret = base.GetCategoriesByIds(ids);
            return ret;
        }
     
        public override ICategory GetCategory(Guid categoryID)
        {
            var ret = base.GetCategory(categoryID);
            return ret;
        }
     
        public override System.Collections.IList GetForums(bool excludeHidden)
        {
            var ret = (from Forum f in base.GetForums(excludeHidden) where f.CategoryID.ToString() == CategoryId select f).ToList();
            return ret;
        }
     
        public override IForum GetForum(Guid forumID)
        {
            var ret = base.GetForum(forumID);
            return ret;
        }
     
        public override System.Collections.IList GetForums(Guid categoryID, bool excludeHidden)
        {
            var ret = base.GetForums(categoryID, excludeHidden);
            return ret;
        }
     
        public override System.Collections.IList GetForums(Guid[] ids, bool excludeHidden)
        {
            var ret = base.GetForums(ids, excludeHidden);
            return ret;
        }
     
        public override System.Collections.IList GetForums(ICategory category, bool excludeHidden)
        {
            var ret = base.GetForums(category, excludeHidden);
            return ret;
        }
     
        public override System.Collections.IList GetForumsUncategorized(bool excludeHidden)
        {
            //return base.GetForumsUncategorized(excludeHidden);
            return new List<Forum>();
        }
     
        public override System.Collections.IList GetRecentForums(int start, int max)
        {
            var ret = (from Forum f in base.GetRecentForums(start, max) where f.CategoryID.ToString() == CategoryId select f).ToList();
            return ret;
        }
     
     
    }

    ...in case anyone else has a similar problem.

    Thanks!
Register for webinar
8 posts, 2 answered