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

Forums / Developing with Sitefinity / Programmatically Filtering the DownloadList

Programmatically Filtering the DownloadList

9 posts, 0 answered
  1. joeldickson
    joeldickson avatar
    9 posts
    Registered:
    12 Feb 2007
    24 Jul 2009
    Link to this post
    Hi Guys,

    I was working on the same thing wiht the ImageGallery Control. But the man Ivan help me out with this post.

    http://sitefinity.com/support/forums/sitefinity-3-x/developing-with-sitefinity/inheriting-the-imagegallery-control.aspx

    I tried to use the same method in the DownloadList and am getting no love.

    the method is

     protected override System.Collections.IList CreateDataSource()    
        {    
            var builder = new ContentFilterBuilder(this);    
            builder.AddFilter(new ContentFilterStatement("Tag.Name""test", Telerik.Cms.Engine.ContentViewFiltering.ContentFilter.Condition.Equal));            
            return base.CreateDataSource();     
        }    
     

    Using this i just get the full list of documents on the site.

    Should this same method work? or is there somthing funky i need to do to get this tow work on the DocumentList control?

    Thanks in advance,

    Joel
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    24 Jul 2009
    Link to this post
    Hello joeldickson,

    You can give a try to the code below. Here we are overriding CreateChildControls and adding our filter.

    using System; 
    using Telerik.Cms.Engine.ContentViewFiltering; 
    using Telerik.Libraries; 
     
    /// <summary> 
    /// Summary description for CustomDownloadList 
    /// </summary> 
    public class CustomDownloadList : DownloadList 
        public CustomDownloadList() 
        { 
            // 
            // TODO: Add constructor logic here 
            // 
        } 
     
        public override string ItemListTemplatePath 
        { 
            get 
            { 
                return "~/Sitefinity/Admin/ControlTemplates/Libraries/Modes/DownloadList.ascx"
            } 
        } 
     
        public override Type LocalizationAssemblyInfo 
        { 
            get 
            { 
                return typeof(DownloadList); 
            } 
            set 
            { 
                base.LocalizationAssemblyInfo = value; 
            } 
        } 
     
        protected override void CreateChildControls() 
        { 
            base.CreateChildControls(); 
            var filter = new ContentFilterBuilder(this); 
            filter.AddFilter(new ContentFilterStatement("Tag.Name""test", Telerik.Cms.Engine.ContentViewFiltering.ContentFilter.Condition.Equal)); 
        } 

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. joeldickson
    joeldickson avatar
    9 posts
    Registered:
    12 Feb 2007
    04 Aug 2009
    Link to this post
    Hi Ivan,

    Thanks for your help. But I've copied and pasted your code and the filter doesn't work, i still get all the results displayed, not filtering of the list.

    Any more ideas?

    Thanks,

    Joel
  4. Dido
    Dido avatar
    149 posts
    Registered:
    24 Sep 2012
    07 Aug 2009
    Link to this post
    Hello joeldickson,

    I looked through the code, and I did not find any reason for the codenot to work. Therefore, I wrote a simple download list control,that you can modify easily to suit your needs. It has not been testedexclusively.

    Best wishes,
    Dido
    the Telerik team

    Instantly find answers to your questions on the newTelerik Support Portal.
    Check out the tipsfor optimizing your support resource searches.
  5. Shadi S
    Shadi S avatar
    3 posts
    Registered:
    26 Feb 2010
    26 Feb 2010
    Link to this post
    I downloaded the sample files that Dido made and imported them into my Sitefinity 3.7 site. Doesn't seem to fully work. Here's what happens:
    I insert the control into a page (works)
    I set the "FromLibraries" field (works)
    I set the "FromTags" field (doesn't work). I get the following error in Edit View:

    Unable to cast object of type 'Telerik.Cms.Engine.Data.TagsQuery' to type 'Systems.Collection.Generic.IList'1[Telerik.Cms.Engine.ITag]'.

    when when I publish the page and go back to regular view, the entire page crashes.

    Please help, I'm trying to impliment a custom DownloadList that filters by Tags.
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    26 Feb 2010
    Link to this post
    Hi Shadi Safadi,

    You can fix the cast exception by modifying CreateDataSource() . Please check
    if (filterByTag) loop.


    if (filterByTag)
     {
         tagFilter = this.manager.GetTags().OfType<ITag>().ToList();
     }


    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.
  7. Shadi S
    Shadi S avatar
    3 posts
    Registered:
    26 Feb 2010
    26 Feb 2010
    Link to this post
    Ivan, thank you for the code. that fixed the error, but I ran into another problem.

    It seems your code filters Tags by their ID and not by they TagName. I'm a developer and I can found out the TagID, but for my client, they won't be able to figure that out, is there a way to modify the code to filter by the TagNames?

    thank you.
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    28 Feb 2010
    Link to this post
    Hi Shadi S,

    You can implement a custom WebUItype editor from where you select TagNames or TagIDs.Yyou can find code samples at


    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.
  9. Shadi S
    Shadi S avatar
    3 posts
    Registered:
    26 Feb 2010
    02 Mar 2010
    Link to this post
    Ivan, thank you for the suggestion, but I ended up implimenting the following change to your code and I think this is good enough for now:

    your code (does not filter by Tags, it just takes all available tags):
    if (filterByTag)
    {
        tagFilter = this.manager.GetTags().OfType<ITag>().ToList();
    }

    my code (filters by the user input FromTags):
    if (filterByTag)
    {
        tagFilter = new List<ITag>();
        TagGuidArrayConverter tgConv = new TagGuidArrayConverter();
        IList<ITag> alltags = this.manager.GetTags().OfType<ITag>().ToList();
        foreach (Guid g in FromTags)
        {
            foreach (ITag t1 in alltags)
            {
                if (t1.ID.Equals(g)) { tagFilter.Add(t1); }
            }
        }
    }

    I applied the same to the Categories and it is working now.

    thanks for all the help.
Register for webinar
9 posts, 0 answered