Forcing Files to Download

2 posts, 0 answers
  1. judo
    judo avatar
    19 posts
    Member since:
    Apr 2006

    Posted 31 Aug 2009 Link to this post

    I was trying to follow the demo for FileExplorer / Filter files and download at  http://demos.telerik.com/aspnet-ajax/fileexplorer/examples/filteranddownloadfiles/defaultcs.aspx
    But I am not having much luck, so far I place the following script in the <head>

     <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 ((true == true) && (fileExtension == "pdf" || fileExtension == "pdf"))
                {// 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> 

    My FileExplorer Looks like this:
    <telerik:RadScriptManager ID="RadScriptManager1" Runat="server"
            </telerik:RadScriptManager> 
            <telerik:RadFileExplorer ID="RadFileExplorer1" Runat="server"  onclientfileopen="OnClientFileOpen" 
                DisplayUpFolderItem="True" Skin="Office2007"  
                VisibleControls="TreeView, Grid, Toolbar, ContextMenus" EnableCopy="True"
    <Configuration SearchPatterns="*.*" ></Configuration
      <Configuration  ViewPaths="~/doc_manager_files/" UploadPaths="~/doc_manager_files/"  
                            DeletePaths="~/doc_manager_files/" MaxUploadFileSize="204800000" /> 
     
            </telerik:RadFileExplorer> 

    And I added this to the code behind:
    Private Function IsFiltered(ByVal name As String) As Boolean 
            If name.ToLower().EndsWith(".sys") OrElse name.ToLower().Contains("_sys") Then 
                Return True 
            End If 
            Return False 
        End Function 

    I am not sure what else to do. It seems the doc to be downloaded will be handled by a handler.ashx file but I cannot see any code for that file.

  2. Fiko
    Admin
    Fiko avatar
    1406 posts

    Posted 31 Aug 2009 Link to this post

    Hi Judo,

    For your convenience I have attached the full demo, including the Handler.ashx file. The code in this handler forces the browsers to open the images for download.
    Additional information on the subject can be found at the end of this KB article.

    I hope this helps.

    Regards,
    Fiko
    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.
Back to Top