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

Forums / General Discussions / How to filter download list

How to filter download list

6 posts, 0 answered
  1. Chris Wilper
    Chris Wilper avatar
    13 posts
    Registered:
    01 Sep 2009
    06 Oct 2009
    Link to this post
    I created a control with the following, but it is not filtering the results.  When I try and debug the code the break points are never hit.  I need to filter documents by category and tag.

    using

     

    System;

     

    using

     

    System.Collections.Generic;

     

    using

     

    System.Linq;

     

    using

     

    System.Web;

     

    using

     

    Telerik.Cms.Engine.ContentViewFiltering;

     

    using

     

    Telerik.Cms.Engine.WebControls;

     

    using

     

    Telerik.Libraries;

     

    ///

     

    <summary>

     

    ///

     

    Summary description for FranshiseDocuments

     

    ///

     

    </summary>

     

    public

     

    class FranshiseDocuments : DownloadList

     

    {

     

    protected override void CreateChildControls()

     

    {

     

    string filter = "Documents";

     

     

    if (this.Page != null && this.Page.Request.QueryString["location"] != null)

     

    {

     

    var filterBuilder = new ContentFilterBuilder(this);

     

    filterBuilder.AddFilter(

    new ContentFilterStatement("Category", filter,

     

     

    ContentFilter.Condition.Equal,

     

     

    ContentFilter.JoinType.And));

     

    filterBuilder.AddFilter(

    new ContentFilterStatement("Tag.Name",

     

    Page.Request.QueryString[

    "location"].ToString(),

     

     

    ContentFilter.Condition.Equal,

     

     

    ContentFilter.JoinType.And));

     

    }

     

    base.CreateChildControls();

     

    }

    }

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    06 Oct 2009
    Link to this post
    Hello Chris Wilper,

    Please give a try to the sample below:

    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Web; 
    using Telerik.Libraries; 
    using System.ComponentModel; 
    using System.Drawing.Design; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using Telerik.Cms.Engine.ContentViewFiltering; 
    using Telerik.Cms.Engine; 
     
    /// <summary> 
    /// Summary description for DownloadList 
    /// </summary> 
    ///  
     
    public class CustomDownloadListToolboxItem : ToolboxItem 
     
        public CustomDownloadListToolboxItem() 
            : base(typeof(CustomDownloadList)) 
        { 
            base.DisplayName = "DisplayName"
            base.Description = "DownloadList_Description"
        } 
     
    [ToolboxItem(typeof(CustomDownloadListToolboxItem))] 
    public class CustomDownloadList : DownloadList 
        public CustomDownloadList() 
        { 
     
        } 
     
        public override string ItemListTemplatePath 
        { 
            get 
            { 
                return "~/Sitefinity/ControlTemplates/Libraries/DownloadList.ascx"
            } 
     
        } 
     
        protected override void CreateChildControls() 
        { 
            ContentFilterBuilder filterBuilder = new ContentFilterBuilder(this); 
            ITag tag = LibraryManager.Providers["Libraries"].GetTag("test"); 
            if (tag != null
            { 
                filterBuilder.AddFilter(new ContentFilterStatement("Tag.Name", tag.TagName, ContentFilter.Condition.Equal, ContentFilter.JoinType.And)); 
            } 
             
           //FILTER THE CATEGORY 
     
            base.CreateChildControls(); 
            
     
             
        } 
     

    You need to implement ToolBoxItem as the example shows. Otherwise your control is not loaded. Let us know if there is anything else that we can do for you.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Chris Wilper
    Chris Wilper avatar
    13 posts
    Registered:
    01 Sep 2009
    06 Oct 2009
    Link to this post
    Thanks for the response.  I tried the code above, but when I drag the custom control to the page I get the following error.

    Unable to cast object of type 'CustomDownloadListToolboxItem' to type 'System.Web.UI.Control'

    Any ideas?
  4. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    12 Oct 2009
    Link to this post
    Hi Chris Wilper,

    Please use this code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Libraries;
    using System.ComponentModel;
    using System.Drawing.Design;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Cms.Engine.ContentViewFiltering;
    using Telerik.Cms.Engine;
      
    /// <summary>
    /// Summary description for DownloadList
    /// </summary>
    /// 
      
     
    [ToolboxItem(typeof(CustomDownloadList))]
    public class CustomDownloadList : DownloadList
    {
        public CustomDownloadList()
        {
      
        }
      
        public override string ItemListTemplatePath
        {
            get
            {
                return "~/Sitefinity/ControlTemplates/Libraries/DownloadList.ascx";
            }
      
        }
      
        protected override void CreateChildControls()
        {
            ContentFilterBuilder filterBuilder = new ContentFilterBuilder(this);
            ITag tag = LibraryManager.Providers["Libraries"].GetTag("test");
            if (tag != null)
            {
                filterBuilder.AddFilter(new ContentFilterStatement("Tag.Name", tag.TagName, ContentFilter.Condition.Equal, ContentFilter.JoinType.And));
            }
              
           //FILTER THE CATEGORY
      
            base.CreateChildControls();
          
        }

    All the best,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Gabriel
    Gabriel avatar
    7 posts
    Registered:
    18 Jul 2008
    19 Oct 2009
    Link to this post
    Hello

    I need to do a download list that can be filtred by date interval but i have no ideia how to do it.

    I need a user control that includes 2 datepicker that filters the downloadlist.
    Can i create a normal web user control and dynamic load the download list and then user the data values to filter the downloadlist ?

    Thanks
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    19 Oct 2009
    Link to this post
    Hello Gabriel,

    The items uploaded to Images and Documents module have only DateCreated property which is used to show Uploaded date. The first way you can achieve desired functionality is overriding CreateDataSource() and check the DateCreated property. Depending on its value you will bind the list.
    Another option which I think is better than the first one is adding two metakeys when your are uploading your documents. There you can use DataTimePicker control to set the data and finally using the code from previous post you can check the values from the above mentioned metakeys and filter the control. 

    Example:

    protected override void CreateChildControls()
    {
     
        ContentFilterBuilder filterBuilder = new ContentFilterBuilder(this);
        filterBuilder.AddFilter(new ContentFilterStatement("Publication_Date",
                            String.Concat("\"", new DateTime(year, month, 1, 0, 0, 0).ToString(), "\""),
                            ContentFilter.Condition.GreaterOrEqual,
                            ContentFilter.JoinType.And);
          base.CreateChildControls();
     }

    You can use a user control, you should again create new metakeys that will store desired data - date value and use FilterExpression property of DownloadList to set the value.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
6 posts, 0 answered