Sitefinity CMS

Set the DownloadList Control to Filter Files by Tags Send comments on this topic.
How-to > Modules > Built-in Modules > Generic Content Based Modules > Images and Documents > Set the DownloadList Control to Filter Files by Tags

Glossary Item Box

This topic provides guidance for implementing tags filtering for the DownloadList public control.

 

Description

The DownloadList control displays links of files in a list or a table. When a link is clicked, the file is directly downloaded. Currently, the control provides the functionality to filter files only by groups. That means that all files that belong to a given group will be listed by the control if that group is selected.

A useful feature is to be able to filter files also by tags.  For example, let's say you have a group named "Monthly News", and you want to display the most important pieces of news as a separate download list. One option is to have a second group named "Exclusive News". However, the second group should also contain a copy of the news that already exist in the first group. Using this method, multiple copies of a file may need to be saved in the database. 

When using tags, all news for a given month will be kept only in the "Monthly News" group, and only some of them will be tagged "exclusive". The control could then filter all group files and display only those with the "exclusive" tag. Thus, only a single copy of a file will be saved in the database.

 

Implementation

Filtering files by tags is a functionality that could be added to a custom control which inherits the DownloadList control class. Here is how to implement that:

  1. Create a class which derives from Telerik.Libraries.WebControls.DownloadList control.

  2. Add the following code to it:

    DisplayMode Copy Code
    public override ContentView.DisplayModes DisplayMode
    {
     get
     {
       
    object obj = this.ViewState["DisplayMode"];
       
    if (obj == null)
       {
         
    return DisplayModes.Auto;
       }
       
    return (DisplayModes)obj;
     }
     set  
     {
       
    this.ViewState["DisplayMode"] = value;
     }
    }  

     

  3. Add the control to the toolbox by registering it in the web.config file.

  4. When you edit your control in edit page mode, set the DisplayMode property to Tags and set Tag ID to the tag ID you want to be used as filter. Also, select the file libraries which will be used to get the intersection between the tag and the groups.