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

Unable to Download image in radgrid as radgird added in radajaxmanager

1 Answer 43 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Manish
Top achievements
Rank 2
Manish asked on 02 May 2014, 03:03 PM
Hi,  
I have used following ajax manager in my page and i have used user control Schedule_Review_Narrative1 on this page to which i have tool into ajax manager 
and i have my grid in Schedule_Review_Narrative1 and in that grid i have applied code to download image but not able to download image.

Problem : i want to use ajax in grid as well as i need to run code to download document. 

<telerik:RadAjaxManager ID="RAMMileston" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="Schedule_Review_Left_Navigation1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="Schedule_Review_Narrative1" />
                    <telerik:AjaxUpdatedControl ControlID="Schedule_Review_Left_Navigation1" />
                      </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>

in link button i have gave command name  to link button and in rggrid_ItemCommand () i have gave following code but not able to download so please help me in this 

    else if (e.CommandName == "DownloadFile")
                    {
                       
                            SqlConnection objSqlCon = new SqlConnection(db.ConnectionString);
                            objSqlCon.Open();
                            SqlTransaction objSqlTran = objSqlCon.BeginTransaction();

                            SqlCommand objSqlCmd = new SqlCommand("Procedure_Name", objSqlCon, objSqlTran);
                            objSqlCmd.CommandType = CommandType.StoredProcedure;

                            SqlParameter objSqlParam1 = new SqlParameter("@FileGUID", SqlDbType.VarChar);
                            objSqlParam1.Value = e.CommandArgument;

                            objSqlCmd.Parameters.Add(objSqlParam1);
                            string path = string.Empty;
                            string FileType = string.Empty;
                            string FormName = string.Empty;

                            using (SqlDataReader sdr = objSqlCmd.ExecuteReader())
                            {
                                while (sdr.Read())
                                {
                                    path = sdr[0].ToString();
                                    FileType = sdr[1].ToString();
                                    FormName = sdr[2].ToString();
                                }

                            }

                            objSqlCmd = new SqlCommand("SELECT GET_FILESTREAM_TRANSACTION_CONTEXT()", objSqlCon, objSqlTran);
                            byte[] objContext = (byte[])objSqlCmd.ExecuteScalar();
                            SqlFileStream objSqlFileStream = new SqlFileStream(path, objContext, FileAccess.Read);
                            byte[] buffer = new byte[(int)objSqlFileStream.Length];
                            objSqlFileStream.Read(buffer, 0, buffer.Length);
                            objSqlFileStream.Close();

                            objSqlTran.Commit();
                            FormName = FormName.Replace(";", "").Replace(",", " ");
                            Response.AddHeader("Content-disposition", "attachment; filename=" + Path.GetFileName(FormName) + FileType);
                            // Here you need to manage the download file stuff according to your need
                            Response.ContentType = "application/octet-stream";
                            Response.BinaryWrite(buffer);
                            Response.End();
                        
                    }

Please help me in this.
Thanks
Manish

1 Answer, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 07 May 2014, 01:08 PM
Hi,

If you want to invoke download for a file from ajaxified control (either placed in RadAjaxPanel or ajaxified by RadAjaxManager), you cannot use the normal Response.Write, because the xmlhttp request cannot handle this.

Instead you can use the ResponseScripts collection of the RadAjax controls to change the location header and download the file.

More information on this mater could be found ion the help topic below:

http://www.telerik.com/help/aspnet-ajax/ajax-download.html

Regards,
Maria Ilieva
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Ajax
Asked by
Manish
Top achievements
Rank 2
Answers by
Maria Ilieva
Telerik team
Share this question
or