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

file download problem

1 Answer 118 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mww
Top achievements
Rank 1
mww asked on 05 Apr 2012, 02:36 PM
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

<telerik:GridAttachmentColumn
                       MaxFileSize="1048576"
                       EditFormHeaderTextFormat="Download File:"
                       HeaderText="Download"
                       
                       AttachmentKeyFields="AudioID"
                       FileNameTextField="AudioPath"
                       DataTextField="SongTitle"
                       UniqueName="AttachmentColumn">
                   </telerik:GridAttachmentColumn>

I have this in client settings

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


function gridCommand(sender, args) {
               if (args.get_commandName() == "DownloadAttachment") {
                   var manager = $find('<%= RadAjaxManager.GetCurrent(Page).ClientID %>');
                   manager.set_enableAJAX(false);
 
                   setTimeout(function () {
                       manager.set_enableAJAX(true);
                   }, 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);
 
                    try
                    {
                        if (FileName.Exists)
                        {
                            HttpContext.Current.Response.Clear();
                            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";
                            HttpContext.Current.Response.TransmitFile(FileName.FullName);
                            HttpContext.Current.Response.Flush();
                        }
                        else
                        {
                            throw new Exception("File not found");
                        }
                    }
                    catch (Exception ex)
                    {
                        HttpContext.Current.Response.ContentType = "text/plain";
                        HttpContext.Current.Response.Write(ex.Message);
                    }
                    finally
                    {
                        HttpContext.Current.ApplicationInstance.CompleteRequest();
                    }
                }
 
            }
        }
  can anyone see where im going wrong ?

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 10 Apr 2012, 08:24 AM
Hi,

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,
Andrey
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.
Tags
Grid
Asked by
mww
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or