This is a migrated thread and some comments may be shown as answers.
Download Attachment from GridAttachmentColumn
5 Answers 135 Views
This is a migrated thread and some comments may be shown as answers.
Richard Weeks
Top achievements
Rank 2
Richard Weeks asked on 29 Sep 2011, 05:52 AM

I followed the example online to download the attachment from a grid with a GridAttachmentColumn but I can't get the download working. The postback fires, ajax disables but the file is not sent. I am using Entity Framework.

<telerik:RadGrid 
    AutoGenerateColumns="False" 
    AutoGenerateDeleteColumn="True" 
    AutoGenerateEditColumn="True" 
    DataSourceID="EntityAttachmentsDataSource" 
    ID="EntityAttachmentsGrid" 
    OnDeleteCommand="EntityAttachmentsGrid_OnDeleteCommand" 
    OnInsertCommand="EntityAttachmentsGrid_OnInsertCommand" 
    OnItemCommand="EntityAttachmentsGrid_OnItemCommand"
    OnUpdateCommand="EntityAttachmentsGrid_OnUpdateCommand" 
    runat="server">
    <MasterTableView 
        DataKeyNames="Id" 
        DataSourceID="EntityAttachmentsDataSource">
        <Columns>
            <telerik:GridBoundColumn 
                DataField="Id" 
                DataType="System.Int32" 
                HeaderText="Id" 
                ReadOnly="True" 
                UniqueName="Id">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn 
                DataField="FileName" 
                HeaderText="FileName" 
                UniqueName="FileName" 
                ReadOnly="true" 
                DataType="System.String">
            </telerik:GridBoundColumn>
            <telerik:GridAttachmentColumn 
                DataSourceID="EntityAttachmentDataSource"
                MaxFileSize="1048576" 
                EditFormHeaderTextFormat="Upload Attachment:"
                HeaderText="Attachment"
                HeaderTooltip="Download Entity Attachment"
                AttachmentDataField="Attachment" 
                AttachmentKeyFields="Id"
                FileNameTextField="FileName" 
                DataTextField="FileName"
                UniqueName="InfringmentAttachment">
            </telerik:GridAttachmentColumn>
        </Columns>
    </MasterTableView>
    <ClientSettings>
        <ClientEvents OnCommand="GridOnCommand" />
    </ClientSettings>
</telerik:RadGrid>
  
<asp:EntityDataSource 
    ConnectionString="name=MyEntities" 
    DefaultContainerName="MyEntities" 
    EnableFlattening="False" 
    EntitySetName="EntityAttachments" 
    EntityTypeFilter="EntityAttachment" 
    ID="EntityAttachmentsDataSource" 
    runat="server">
</asp:EntityDataSource>
  
<asp:EntityDataSource 
    ConnectionString="name=MyEntities" 
    DefaultContainerName="MyEntities" 
    EnableFlattening="False" 
    EntitySetName="EntityAttachments" 
    EntityTypeFilter="EntityAttachment" 
    ID="EntityAttachmentDataSource" 
    runat="server" 
    Where="it.[Id] = @Id"
    Select="it.[Attachment]">
    <SelectParameters>
        <asp:Parameter Name="Id" Type="Int32" />
    </SelectParameters>
</asp:EntityDataSource>

I disabled ajax fine (ConditionalPostback, etc.) and can upload no worries. But I can't get the attachment to download direct from the datasource. All the examples I can find are for SqlDataSource.

Richard

5 Answers, 1 is accepted

Sort by
0
Richard Weeks
Top achievements
Rank 2
answered on 03 Oct 2011, 03:22 AM
The benefit of a weekends rest allowed me to fix my issue regarding downloading but stay with me!

I can't work out how to grab the filename of the uploaded file. Here is some code:

var gridAttachmentColumnEditor = ((GridAttachmentColumnEditor)editedItem
.EditManager.GetColumnEditor(
"Attachment"));
  
attachment.Attachment = gridAttachmentColumnEditor.UploadedFileContent;
  
attachment.FileName = gridAttachmentColumnEditor.????;

If I can get this, I am done with implementing this useful feature!

Richard
0
Accepted
Veli
Telerik team
answered on 03 Oct 2011, 03:10 PM
Have you tried:

gridAttachmentColumnEditor.RadUploadControl.UploadedFiles[0].FileName

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
0
Richard Weeks
Top achievements
Rank 2
answered on 03 Oct 2011, 11:28 PM
Thanks for your reply. There were a combination of factors that meant the uploaded file was failing. Once I rebuilt my SQL Server table, I can then have access to the filename. In the end I used:

 

gridAttachmentColumnEditor.RadUploadControl.UploadedFiles[0].GetName();

I'll need to rework my code a bit to ensure the UploadedFileContent matches what is supposed to be in my database table.

Richard

0
Bill
Top achievements
Rank 1
answered on 22 Aug 2012, 02:19 AM
Hello Richard,

Can you provide a way so I can download your sample?
Thanks,
Bill..
0
Richard Weeks
Top achievements
Rank 2
answered on 23 Aug 2012, 05:20 AM
Hi, I'm really sorry but I don't have a sample as this code forms part of a very large project I worked on. Unfortunately my employer takes a proprietary stance on source code, so I can't copy it out to post here :(

Richard
Tags
Grid
Asked by
Richard Weeks
Top achievements
Rank 2
Answers by
Richard Weeks
Top achievements
Rank 2
Veli
Telerik team
Bill
Top achievements
Rank 1
Share this question
or