Force open/download all files type

12 posts, 0 answers
  1. Filleau
    Filleau avatar
    114 posts
    Member since:
    Jun 2006

    Posted 26 Mar 2010 Link to this post

    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
  2. robertw102
    robertw102 avatar
    265 posts
    Member since:
    Jul 2007

    Posted 30 Mar 2010 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Filleau
    Filleau avatar
    114 posts
    Member since:
    Jun 2006

    Posted 31 Mar 2010 Link to this post

    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
  5. Dobromir
    Admin
    Dobromir avatar
    1633 posts

    Posted 01 Apr 2010 Link to this post

    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.
  6. Filleau
    Filleau avatar
    114 posts
    Member since:
    Jun 2006

    Posted 01 Apr 2010 Link to this post

    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
  7. Lini
    Admin
    Lini avatar
    2144 posts

    Posted 02 Apr 2010 Link to this post

    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.
  8. Filleau
    Filleau avatar
    114 posts
    Member since:
    Jun 2006

    Posted 02 Apr 2010 Link to this post

    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
  9. Lini
    Admin
    Lini avatar
    2144 posts

    Posted 06 Apr 2010 Link to this post

    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.
  10. Zura Chikhladze
    Zura Chikhladze avatar
    32 posts
    Member since:
    Jul 2009

    Posted 17 Jan 2011 Link to this post

    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>
  11. Lini
    Admin
    Lini avatar
    2144 posts

    Posted 18 Jan 2011 Link to this post

    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.
  12. Zura Chikhladze
    Zura Chikhladze avatar
    32 posts
    Member since:
    Jul 2009

    Posted 18 Jan 2011 Link to this post

    Thank you Lini, it's working now.
  13. Yoon-Ho Choi
    Yoon-Ho Choi avatar
    22 posts
    Member since:
    Dec 2009

    Posted 24 Jan 2011 Link to this post

    Thank U It works fine..
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017