This is a migrated thread and some comments may be shown as answers.

Forcing Files to Download

1 Answer 144 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
judo
Top achievements
Rank 1
judo asked on 31 Aug 2009, 06:37 AM
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.

1 Answer, 1 is accepted

Sort by
0
Fiko
Telerik team
answered on 31 Aug 2009, 02:31 PM
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.
Tags
FileExplorer
Asked by
judo
Top achievements
Rank 1
Answers by
Fiko
Telerik team
Share this question
or