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

Can't Download Attachment Column Data From Edit Table.

2 Answers 105 Views
Grid
This is a migrated thread and some comments may be shown as answers.
gc_0620
Top achievements
Rank 1
gc_0620 asked on 03 Oct 2011, 12:27 AM

Folks

Enviromnent: VS 2010 with RadControls for ASP.NET AJAX Q2 2011 SP1. I am using below link as a prototype for my project.

http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/gridattachmentcolumn/defaultcs.aspx

In my project, Download options works if they are not inside edit table. Below declarations works.

<div style="margin-bottom: 5px;">
        <telerik:RadComboBox ID="FileNamesComboBox1" runat="server" DataSourceID="SqlDataSource1"
            DataTextField="FileName" DataValueField="ID" CssClass="rgExpXLS">
        </telerik:RadComboBox>
                
        <asp:LinkButton ID="LinkButton_Dwnload" runat="server" OnClick="DownloadButton_Click"
            Text="DownLoad"></asp:LinkButton>
    </div>
 
 protected void DownloadButton_Click(object sender, EventArgs e)
 
         {
             int attachmentId = Int32.Parse(FileNamesComboBox1.SelectedValue);
             string fileName = FileNamesComboBox1.SelectedItem.Text;
 
             SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["TelerikConnectionString"].ConnectionString);
             SqlCommand comm = new SqlCommand("SELECT [BinaryData] FROM [FileData] WHERE [ID] = @ID", conn);
             comm.Parameters.Add(new SqlParameter("@ID", attachmentId));
 
             SqlDataAdapter adapter = new SqlDataAdapter(comm);
             DataSet data = new DataSet();
             adapter.Fill(data);
 
             byte[] binaryData = (byte[])data.Tables[0].Rows[0]["BinaryData"];
             int ii = attachmentId;
             Response.Clear();
             Response.ContentType = "application/octet-stream";
             Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
             Response.BinaryWrite(binaryData);
       
             Response.End();
              
         }

__________________________

But if the download options are within Edit Table, it does not work. Declaration and code:

<EditFormSettings EditFormType="Template">
                <FormTemplate>
                    <table id="Table2" cellspacing="2" cellpadding="1" width="100%" border="0" rules="none"
                        style="border-collapse: collapse; background: white;">
                        <tr>
                            <td>
                                <div style="margin-bottom: 5px;">
                                    <telerik:RadComboBox ID="FileNamesComboBox" runat="server" DataSourceID="SqlDataSource1"
                                        DataTextField="FileName" DataValueField="ID">
                                    </telerik:RadComboBox>
                                    <asp:LinkButton ID="LinkButtonEditTable" runat="server"
                                                      OnClick="DownloadLinkButtonEditTable_Click"
                                        Text="Download from Edit Table" Font-Size="Medium" ForeColor="Red"></asp:LinkButton>
                                </div>
                            </td>
                        </tr>
                    </table>
                </FormTemplate>
            </EditFormSettings>
 
        protected void DownloadLinkButtonEditTable_Click(object sender, EventArgs e)
 
        {
             LinkButton btn = sender as LinkButton;
             if (btn.NamingContainer is GridEditableItem )
            {
              // Edit mode 
             GridEditableItem container = (GridEditableItem)btn.NamingContainer;
             RadComboBox SLurlComboBox = (RadComboBox)container.FindControl("FileNamesComboBox");
             int attachmentId = Int32.Parse(SLurlComboBox.SelectedValue);
             int ii = attachmentId;
              string fileName = SLurlComboBox.SelectedItem.Text;
             SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["TelerikConnectionString"].ConnectionString);
             SqlCommand comm = new SqlCommand("SELECT [BinaryData] FROM [FileData] WHERE [ID] = @ID", conn);
             comm.Parameters.Add(new SqlParameter("@ID", attachmentId));
 
             SqlDataAdapter adapter = new SqlDataAdapter(comm);
             DataSet data = new DataSet();
             adapter.Fill(data);
 
             byte[] binaryData = (byte[])data.Tables[0].Rows[0]["BinaryData"];
             Response.Clear();
             Response.ContentType = "application/octet-stream";
             Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
             Response.BinaryWrite(binaryData);
            Response.End();
            
            
        }

 

My project requires download be done within Edit Table. Attached is the error message while trying to download from Edit Table;

Any help will be appreciated. Thanks

gc_0620


2 Answers, 1 is accepted

Sort by
0
gc_0620
Top achievements
Rank 1
answered on 05 Oct 2011, 04:41 AM
Is it not possible to download the attachment column data within Edit Table? Please clarify. Thanks

ps: I tested the code of DownloadLinkButtonEditTable_Click in debug mode, no error there but some reason can't download.

gc_0620
0
Veli
Telerik team
answered on 06 Oct 2011, 07:03 AM
Hello Gc_0620,

You need to disable AJAX when downloading. Currently, your RadGrid is AJAX-ified and you are streaming the download through a response to an XMLHttpRequest object. This is not supported. You need to turn off AJAX and make a full page postback when you click your download button. In the online demo you can see how we are using RadAjaxManager's client-side OnRequestStart event to disable AJAX if the requests originates from a particular target. You need to employ a similar approach in your scenario.

Veli
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
gc_0620
Top achievements
Rank 1
Answers by
gc_0620
Top achievements
Rank 1
Veli
Telerik team
Share this question
or