file download problem

2 posts, 0 answers
  1. mww
    mww avatar
    257 posts
    Member since:
    Sep 2012

    Posted 05 Apr 2012 Link to this post

    Ive added a file download fucntion to my grid, its works perfectly well on my local development machine, but when i upload it to a hosted server, it wont work !  nothing seems to happen.  In development I get the file dialoge box open in the browser, yet on the live server I dont get that, just the spinning ajax icon

    heres the column in my grid

                           EditFormHeaderTextFormat="Download File:"

    I have this in client settings

                            <ClientEvents OnCommand="gridCommand" />
      and this javascript on the page

    function gridCommand(sender, args) {
                   if (args.get_commandName() == "DownloadAttachment") {
                       var manager = $find('<%= RadAjaxManager.GetCurrent(Page).ClientID %>');
                       setTimeout(function () {
                       }, 0);
      and finally, this is the server side code

    protected void RadGridAudio_ItemCommand(object source, GridCommandEventArgs e)
                if (e.CommandName == RadGrid.DownloadAttachmentCommandName)
                    e.Canceled = true;
                    GridDownloadAttachmentCommandEventArgs args = e as GridDownloadAttachmentCommandEventArgs;
                    string fileName = args.FileName;
                    long attachmentId = (int)args.AttachmentKeyValues["AudioID"];
                    BusinessLayer.RegistrationAudio audio = new RegistrationAudio();
                    audio = registrationManager.GetRegistrationAudio(attachmentId);
                    string filePath = audio.AudioPath.Substring(0, audio.AudioPath.LastIndexOf(@"\"));
                    string _DownloadableProductFileName = audio.FileName;
                    if (audio.AudioPath != null && audio.FileName != null)
                        System.IO.FileInfo FileName = new System.IO.FileInfo(filePath + "\\" + _DownloadableProductFileName);
                        FileStream myFile = new FileStream(filePath + "\\" + _DownloadableProductFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                            if (FileName.Exists)
                                HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;attachment; filename=\"" + FileName.Name + "\"");
                                HttpContext.Current.Response.AddHeader("Content-Length", FileName.Length.ToString());
                                HttpContext.Current.Response.ContentType = "application/octet-stream";
                                throw new Exception("File not found");
                        catch (Exception ex)
                            HttpContext.Current.Response.ContentType = "text/plain";
      can anyone see where im going wrong ?
  2. Andrey
    Andrey avatar
    836 posts

    Posted 10 Apr 2012 Link to this post


    Most probable reason for this behavior is a JavaScript error. You could try to enable script debugging for the browser you are using and check whether you get any JavaScript errors.

    Additionally, you could check this help topic article if you are using RadCompression on the hosting server.

    Give these suggestions a try and check whether they are applicable for your case.
    Kind regards,
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top