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

Downloading from Grid problem

1 Answer 82 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rupert
Top achievements
Rank 1
Rupert asked on 13 Apr 2011, 10:36 AM
Hi,

I am new to telerik controls. It seems really good an I have been evaluating it for use in a project I am working on. The client is really impressed with the look/feel/design. But before I can get him to purchase it I need to be sure I can achieve all the results needed. There is only 1 problem, I am unable to get downloads from a grid working. Below is the code I am using to run the download command. The problem is the choose location dialogue box never appear when I click the download link. I need to mention here that the download link is in a nested grid (grid inside a master grid). Could this be the problem? How do I overcome this?

//Code for inner grid. The event is grid_itemcommand()
void gvReceipt_ItemCommand(object source, GridCommandEventArgs e)
    {
        if (e.CommandName == "Download")
        {
         var ExpHeader_ID = (int)((GridEditableItem)e.Item).GetDataKeyValue("ExpenseHeaderID");
            Int32 ExpID = Convert.ToInt32(ExpHeader_ID);
            ExpHeaderIdReceipt = ExpID;
        
            GridDataItem dataItem = (GridDataItem)e.Item;
            Label lblImgeName = (Label)dataItem.FindControl("lblImage");
            string strRequest = lblImgeName.Text;
            if (!string.IsNullOrEmpty(strRequest))
            {
                string path = Server.MapPath(Manage_FilePaths.HeaderExpImagesRootPath_Original 
+ strRequest);
                System.IO.FileInfo file = new System.IO.FileInfo(path);
                
                if (file.Exists)
                {
                    Response.Clear();
                    Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
                    Response.AddHeader("Content-Length", file.Length.ToString());
                    Response.ContentType = "application/octet-stream";
                    Response.WriteFile(file.FullName);
                    Response.End();
                }
                else
                {
                    Response.Write("This file does not exist.");
                }
            }
            else
            {
                ScriptManager.RegisterStartupScript(this.updGrids, typeof(string), "alert", "<script>alert('Please provide a file to download!');</script>", false);
            }
        }
    }

1 Answer, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 18 Apr 2011, 08:48 AM
Hello Rupert,

Could you please elaborate a bit more no your scenario. Are you using the RadGrid in combination with the ajax?
Due to the limitations of the javascript XmlHttpRequest object used for AJAX, to download or upload attachments, AJAX needs to be temporarily disabled, so that the page performs a full postback. You could find an example of disabling the ajax when downloading a file on the following link:
http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/gridattachmentcolumn/defaultcs.aspx
Please give it try and let me know if it helps you.

Looking forward for your reply.

Best wishes,
Radoslav
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.

Tags
Grid
Asked by
Rupert
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Share this question
or