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

Download File in Content Page

3 Answers 371 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
Technology
Top achievements
Rank 1
Technology asked on 08 Oct 2010, 01:37 PM
Dear developers hello,

I use RadExplorer, in my classic website, with the option to download (or open) files with double click. It works great.

Now i changed my pages and i use Master and Content pages, instead of classic.
RadExplorer is in the Content Page of a Master Page.
After that change, the download is not working. I double click the file and it does nothing (download or open).
The file Handler.ashx is the same.

I use:
Visual Studio 2008 v9.0.30729.1 SP (ASP.NET Visual Basic)

RadControls for ASP.NET Ajax 2010.2.929.35 Trial

Windows 7

If you need any other information, please let me know.
Thank you in advance for your time.

Best Regards
Navarino Technology Department

Below you will find the code of my content page.

<%@ Page Title="" Language="VB" MasterPageFile="~/mpMainMenu.master" AutoEventWireup="true" CodeFile="cInvoices.aspx.vb" Inherits="cInvoices" %>
 
 
 
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
 
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <p>
        <span class="style1">
        <telerik:RadScriptManager
            ID="RadScriptManager1"
            runat="server">
        </telerik:RadScriptManager>
        Welcome</span>
        <asp:Label ID="lblUserName"
                   runat="server"
                   CssClass="style1"
                   Text="User">
        </asp:Label>
        <span class="style1">.
        <br />
        You can download or open the selected file (according the selection below), with
        double click.
        <br />
        </span>
        <asp:RadioButton ID="rbDownload"
                         runat="server"
                         Checked="True"
                         CssClass="style1"
                         GroupName="MyGroup"
                         Text="Download (Save the file to your computer)" />
        <asp:RadioButton ID="rbOpen"
                         runat="server"
                         CssClass="style1"
                         GroupName="MyGroup"
                         Text="Open (Open the file in Viewer)" />
    </p>
    <p>
          
        <telerik:RadFileExplorer ID="RadFileExplorer1"
                                 Runat="server"
                                 Skin="Office2007"
                                 OnClientFileOpen="OnClientFileOpen"
                                 EnableOpenFile="true"
                                 EnableCreateNewFolder="False"
                                 VisibleControls="TreeView, Grid, ContextMenus"
                                 style="text-align: left"
                                 Height="452px"
                                 Width="725px" >
                                 <Configuration SearchPatterns="*.*"></Configuration>
        </telerik:RadFileExplorer>
    </p>
        
    <script type="text/javascript">
            //<![CDATA[
 
            function OnClientFileOpen(oExplorer, args) {
                var item = args.get_item();
                var fileExtension = item.get_extension();
 
                var fileDownloadMode = document.getElementById("rbDownload").checked;
                if ((fileDownloadMode == true) && (fileExtension == "jpg" || 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;
                }
                setTimeout(function() {
                    var oWindowManager = oExplorer.get_windowManager();
                    var previewWinow = oWindowManager.getActiveWindow(); // Gets the current active widow
                    previewWinow.setSize(500, 500); // Set the new size of the window
                }, 100); // Some timeout is required in order to allow the window to become active
            }
            //]]>
 
    </script>
     
</asp:Content>

3 Answers, 1 is accepted

Sort by
0
Accepted
Fiko
Telerik team
answered on 14 Oct 2010, 07:40 AM
Hello,

The problem comes from this code:
var fileDownloadMode = document.getElementById("rbDownload").checked;

When a master page is used (or any Naming container), then the IDs of the server controls are changed and. In your case you have 3 options;
  1. Use an HTML element (without runat="server" attribute) instead of the rbDownload server control
  2. If you are developing the application using .NET40, you can set ClientIDMode="Static" property of the rbDownload server control
  3. You can use this approach in order to get the reference to the rbDownload server control:
    var fileDownloadMode = $get("<%= rbDownload .ClientID %>").checked;
    Please note that in some cases the server parentheses (<%= %>) cause an error on the page, so I recommend you to wrap the JavaScript code in <telerik:RadScriptBlock> control.


Greetings,
Fiko
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
Technology
Top achievements
Rank 1
answered on 14 Oct 2010, 08:32 AM
Dear Fiko,

I used the option 3 and it's working great now.

Thank you for your help.

Best regards,
Navarino Technology Dept.
0
Daniel
Top achievements
Rank 1
answered on 17 Feb 2011, 12:24 PM
Hello,

i have the same problem. But my Code is server side. 
I am using a radgrid to show some Items with ID, filename and description. 
If one of the items is clicked i use the ID to get the base64 string of the file from a database.
I convert the base64 string to bytes.
Then i provide my download function with the bytevalue and the filename. This works fine.
But at some point my download function doesn´t open the download dialog.
The download function is the contentpage. 
This is the download function:

Function download_file(ByVal dateibytes() As Byte, ByVal FileName As String) As Integer
 
        Try
            If dateibytes.Count = 0 Then
 
                Return (0)
            End If
 
            Response.Clear()
            Response.ClearContent()
            Response.ClearHeaders()
            Response.AppendHeader("content-disposition", "attachment; filename=" & FileName.ToString)
            Response.AppendHeader("content-length", dateibytes.Length.ToString())
            Response.Cache.SetCacheability(HttpCacheability.NoCache)
            Response.BinaryWrite(dateibytes)
            Response.Flush()
            Response.Close()
 
        Catch ex As Exception
            Response.Write(ex.ToString)
        End Try

        Return (0)
    End Function





Tags
FileExplorer
Asked by
Technology
Top achievements
Rank 1
Answers by
Fiko
Telerik team
Technology
Top achievements
Rank 1
Daniel
Top achievements
Rank 1
Share this question
or