Telerik is a leading vendor of ASP.NET AJAX, ASP.NET MVC, Silverlight, WinForms and WPF controls and components, as well as .NET Reporting, .NET ORM , .NET CMS, Code Analysis, Mocking, Team Productivity and Automated Testing Tools. Building on its expertise in interface development and Microsoft technologies, Telerik helps customers build applications with unparalleled richness, responsiveness and interactivity. Telerik products help thousands of companies to be more productive and deliver reliable applications under budget and on time.
Version Q2 2011 released 07/12/2011
select

FileExplorer / Filter files and download


Open images for direct download
  •  AllImages
  
  
  
  
  
  
  
  
  
  
  

  • Hide and direct download the files

    The custom FileBrowserContentProvider implementation allows filtering certain files from the RadFileExplorer. This example demonstrates the implementation of a custom FileBrowserContentProvider, that filters the showed items (files, folders). The default behavior where the files are open in a RadWindow is changed and the files with extensions .jpg and .gif are opened for direct download.

    The CustomFileBrowserProviderWithFilter class inherits the FileSystemContentProvider class and overrides its ResolveDirectory and ResolveRootDirectoryAsTree methods. We override them and use our code, designed to handle the certain file extensions or folders that contain certain word(s) in their name. The example above is configured to handle items containing "Flower" and "_sys" in their names and a "sys" file extension. The function IsFiltered() is used to determine whether a file or folder is filtered or not. This function needs to be changed in order to tweak the filtering.

    When a file is opened (double click on it), the extension of that file is checked inside the OnClientFileOpen event handler and in case that it is a 'jpg' or 'gif' file the event is canceled. The file is opened for direct download and not inside a preview window. The files are stored in a folder on the server and the downloaded file is served by the content-streamer - Handler.ashx file. Please note that the EnableFileOpen property needs to be set to "true" (it is "true" by default).

Source Code

C# VB.NET
Show code in new window Demo isolation steps
  • <%@ Page Language="c#" CodeFile="DefaultCS.aspx.cs" AutoEventWireup="true" Inherits="Telerik.Web.Examples.FileExplorer.FilterAndDownloadFiles.DefaultCS" %>

    <%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>
    <%@ Register TagPrefix="qsf" TagName="Header" Src="~/Common/Header.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="Footer" Src="~/Common/Footer.ascx" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <qsf:HeadTag ID="Headtag1" runat="server" />

        <script type="text/javascript">
            //<![CDATA[

            function OnClientFileOpen(oExplorer, args)
            {
                var item = args.get_item();
                var fileExtension = item.get_extension();

                var fileDownloadMode = document.getElementById("chkbxDownoaldFile").checked;
                if ((fileDownloadMode == true) && (fileExtension == "jpg" || fileExtension == "gif"))
                {// Download the file
                    // File is a image document, do not open a new window
                    args.set_cancel(true);

                    // Tell browser to open file directly
                    var requestImage = "Handler.ashx?path=" + item.get_url();
                    document.location = requestImage;
                }
            }
            //]]>
        </script>

    </head>
    <body class="BODY">
        <form runat="server" id="mainForm" method="post">
        <qsf:Header ID="Header1" runat="server" NavigationLanguage="c#" />
        <telerik:radscriptmanager id="RadScriptManager1" runat="Server" />
        <br />
        <table cellspacing="4">
            <tr>
                <td>
                    <input type="checkbox" id="chkbxDownoaldFile" checked="checked" name="sdf" />Open
                    images for direct download
    <asp:CheckBox ID="CheckBox1" runat="server" Checked="true" Text="Use custom content provider"
    AutoPostBack="true" />

                </td>
            </tr>
            <tr>
                <td rowspan="2" style="vertical-align: top;">
                    <telerik:radfileexplorer runat="server" id="RadFileExplorer1" width="734px" height="400px"
                        onclientfileopen="OnClientFileOpen" enableopenfile="true">
                      <Configuration ViewPaths="~/FileExplorer/ExplorerSource/Images/AllImages" />
                   </telerik:radfileexplorer>
                </td>
            </tr>
        </table>
        <qsf:Footer runat="server" ID="Footer1" />
        </form>
    </body>
    </html>

Get more than expected!

 
 

Take your time to truly experience the power of RadControls for ASP.NET AJAX with a free 60-day trial backed up by Telerik’s unlimited dedicated support.

Download your RadControls for ASP.NET AJAX trial and jumpstart your development with the available Getting Started resources.

If you have any questions, do not hesitate to contact us at sales@telerik.com.

Copyright 2002-2024 © Telerik. All right reserved
Telerik Inc, 201 Jones Rd, Waltham, MA 02451