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

Force open/download all files type

11 Answers 607 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
Filleau
Top achievements
Rank 1
Filleau asked on 26 Mar 2010, 05:15 PM
Hi, I'm using the 2010Q1 with VS 2008 in VB

I read KP, and samples on working with files extensions and FileExplorer.


I try to change this example (http://www.telerik.com/ArticleFileDownload.aspx?I=bdmh&G=bahm) in order to force IE to ask user for open/download files when they click on open button.
I don't want the display dialog box for any files.

I tryed to replcae
 ' The docx files are downloaded ;  
        If Path.GetExtension(physicalPathToFile).Equals(".docx", StringComparison.CurrentCultureIgnoreCase) Then  
            ' Handle .docx files ;  
            Me.WriteFile(physicalPathToFile, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", Context.Response)  
        End If  
          
        If Path.GetExtension(physicalPathToFile).Equals(".jpg", StringComparison.CurrentCultureIgnoreCase) Then  
            ' Handle .jpg files ;  
            WriteFile(physicalPathToFile, "image/jpeg", Context.Response)  
        End If  
          
        ' "txt/html" is the default valuse for Response.ContentType property;  
        ' do not download the file. Open in the window ;  
        Context.Response.WriteFile(physicalPathToFile) 
by
 WriteFile(physicalPathToFile, "", Context.Response) 

But it don't work.

It work for ".doc" and ".xls" files (IE ask me if I wan't to download, open ou calcel)
for ".jpg" files IE ask me too if I wan't to open or download it, but there is a telerik box under this dialog box
for ".dwg" files IE don't ask me anythink and try to display it as text

Please can you help me ? I Know my english is bad, excuses me for this, but I can't find the soluce by myself.

Regards

Anthony

11 Answers, 1 is accepted

Sort by
0
robertw102
Top achievements
Rank 1
answered on 30 Mar 2010, 09:28 PM
Instead of replacing the "image/jpeg" line with an empty string. You should set it to this:

WriteFile(physicalPathToFile, "application/octet-stream", Context.Response) 

This will force all files to be downloaded, regardless of their file type.

I hope that helps.
0
Filleau
Top achievements
Rank 1
answered on 31 Mar 2010, 09:23 AM
Thanks. You rigth, it force all files to be downloaded.

But for Jpg files, or dwg, there is an empty telerik dialog box displayed, and users need to close it after the files is download.

I don't find why there is this dialog. I don't want it
0
Dobromir
Telerik team
answered on 01 Apr 2010, 11:40 AM
Hi Anthony,

When a user is trying to open a file from RadFileExplorer, the client event OnClientFileOpen is raised. In order to prevent the opening of the empty RadWindow dialog you need to cancel this event, e.g.:
<telerik:RadFileExplorer ID="RadFileExplorer1" runat="server" EnableCopy="true" OnClientFileOpen="OnClientFileOpen">
</telerik:RadFileExplorer>
 
<script type="text/javascript">
    function OnClientFileOpen(sender, args)
    {
        var href = window.location.href;
        args.set_cancel(true);
         
        //open the item in new window to avoid losing current content
        window.open(href.substring(0, href.lastIndexOf("/") + 1) +  args.get_item().get_url());
    }
</script>


Greetings,
Dobromir
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.
0
Filleau
Top achievements
Rank 1
answered on 01 Apr 2010, 12:31 PM
Hi,

Thanks for your answer but doing this a browser windows is opened eachtime users click on an file or a folder. Not good.

I need to understand why the sample do exactly what I need when I click on a .DOC or  .XLS files, and why there is this tekerik dialobox when I click on a .JPG file or .DWG.

I Don't see anywhere in the project, some code who can explain this and a trace won't help me more.

As I wrote first, my need is simple. This sample is perfect for me except that I wan't to force the download/open/cancel  dialog box for ALL THE FILES when an user click. (I don't need to display/preview any file)

Thanks
0
Lini
Telerik team
answered on 02 Apr 2010, 01:57 PM
Hello,

I don't think that what you want is possible. Whether the download dialog will appear is entirely up to the browser/operating system and their MIME file types configuration. For example - you will never see this dialog if you click on a .htm file, because the browser will always try to open this file directly. The same holds true for other file types as well and on top of that there are some differences between browsers. This is why we went with the RadWindow approach - using a separate window to open the files ensures that opening a file will not navigate away from the current page.

By default the RadFileExplorer uses a private client method (_isOpenExtension) to check if a file should be opened in a window or directly in the browser:

_isOpenExtension: function(ext)
    {
        return (ext == "docx" || ext == "doc" || ext == "xlsx" || ext == "xls" || ext == "zip");
    }

As you can see the function has some often used extensions hardcoded. Everything else will be opened through a RadWindow.

Regards,
Lini
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.
0
Filleau
Top achievements
Rank 1
answered on 02 Apr 2010, 02:07 PM
Is there a way to change this code ? By overload or something like this (i'm a newbie)

I'm suprise to not see .jpg.

I'm agree that for .html browser will display it
0
Lini
Telerik team
answered on 06 Apr 2010, 12:12 PM
Hi Filleau,

You can override the default file explorer method but we strongly advice against it, since the method is marked as private and could change without notice in a future release. You will need to be careful when updating the RadControls version in your project and make sure the overridden code still works.

Placing the following code on your page (after the script manager control) will allow you to control which file extensions will be opened in a new RadWindow and which will be opened directly using the browser:

<script type="text/javascript">
    Telerik.Web.UI.RadFileExplorer.prototype._isOpenExtension = function(ext)
    {
        return (ext == "docx" || ext == "doc" || ext == "xlsx" || ext == "xls" || ext == "zip");
    };
</script>

However, you should remember that the above code cannot change the browser behavior - if a browser knows it can display a file directly, it will not show you the download dialog for that file. This is why I don't think that adding

 || ext == "jpg"

to the above code will allow you to download JPG image files. The browser will simply display them and replace the page with the file explorer.

Regards,
Lini
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.
0
Zura Chikhladze
Top achievements
Rank 1
answered on 17 Jan 2011, 09:46 AM
Hi, i was wondering maybe you can help me with the code below. I am using the javascript to cancel the preview, however it is not downloading the file. Namely, it is not asking me to OPEN OR DOWNLOAD the file. The files that have to be downloaded are MS office files and not jpg/png. Thank you. Zura.  

script type="text/javascript">
            function OnClientFileOpen(sender, args) {
                var href = window.location.href;
                args.set_cancel(true);
  
            }
</script>
  
 <telerik:RadFileExplorer ID="RadFileExplorer1" enableopenfile="true"  onclientfileopen="OnClientFileOpen" ExplorerMode="FileTree"  runat="server"
            Skin="Windows7" Height="300px" Width="300px">
            <Configuration ViewPaths="~/Company Events"></Configuration>
        </telerik:RadFileExplorer>
0
Lini
Telerik team
answered on 18 Jan 2011, 12:38 PM
Hello,

The JavaScript code you pasted does not set the window.location.href value, which is what you need to do in order for the browser to display the open/save dialog for office documents. Here is the updated code:

function OnClientFileOpen(sender, args)
{
    if (!args.get_item().isDirectory())
    {
        var href = args.get_item().get_path();
        window.location.href = href;
        args.set_cancel(true);
    }
}

Note that if you try to open a file that the browser understands (e.g. an image or a .html file) it will replace the current browser page and will not display an open/save dialog. The dialog will pop up only for files which the browser cannot display (e.g. word document).

All the best,
Lini
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Zura Chikhladze
Top achievements
Rank 1
answered on 18 Jan 2011, 10:56 PM
Thank you Lini, it's working now.
0
Yoon-Ho Choi
Top achievements
Rank 1
answered on 25 Jan 2011, 01:39 AM
Thank U It works fine..
Tags
FileExplorer
Asked by
Filleau
Top achievements
Rank 1
Answers by
robertw102
Top achievements
Rank 1
Filleau
Top achievements
Rank 1
Dobromir
Telerik team
Lini
Telerik team
Zura Chikhladze
Top achievements
Rank 1
Yoon-Ho Choi
Top achievements
Rank 1
Share this question
or