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

file download functionality

7 Answers 364 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mww
Top achievements
Rank 1
mww asked on 06 Feb 2011, 05:09 PM
Im trying to implement a file download function in a grid.  The grid is controlled by an ajax manager.  In the grid i have a GridButtonColumn

<telerik:GridButtonColumn ButtonType="ImageButton"
                                        CommandName="ImageDownload" Text="Download" UniqueName="ImageDownload" ImageUrl="~/images/dnn.gif">
                                        <HeaderStyle Width="20px" />
                                        <ItemStyle HorizontalAlign="Center" />
                                    </telerik:GridButtonColumn>

I then have this function that should initiate the file save dialog for users to save the selected file to their file system

protected void RadGridImages_ItemCommand(object source, GridCommandEventArgs e)
        {
                         
            if (e.CommandName.Equals("ImageDownload"))
            {
//commandargument has the physical path on the server of the selected file
                DownloadImage(e.CommandArgument.ToString());
            }
        }
 
        private void DownloadImage(string imagePath)
        {
            FileInfo file = new FileInfo(imagePath);
            if (file.Exists)
            {
                Response.ClearContent();
                Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
                Response.AddHeader("Content-Length", file.Length.ToString());
                Response.ContentType = Studio1BusinessLayer.Helpers.ReturnExtension(file.Extension.ToLower());
                Response.TransmitFile(file.FullName);
                Response.End();
            }
        }

The DownloadImage method generates this error

Could not complete the operation due to error c00ce514.

Can anyone show me how to achieve a simple file download function in a radgrid ?

7 Answers, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 09 Feb 2011, 10:42 AM
Hello Mww,

Could you please try disabling the ajax when the Download button is pressed. 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.  On the following online example you could see how to disable AJAX:
http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/gridattachmentcolumn/defaultcs.aspx

I hope this helps.

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.
0
RvdGrint
Top achievements
Rank 1
answered on 30 May 2011, 01:27 PM
Radoslav,

I've the same problem with a GridAttachmentColumn. I've 'copied' the example you mentioned but still keep the c00ce514 error.
0
Radoslav
Telerik team
answered on 02 Jun 2011, 07:58 AM
Hello Jos,

I tried to reproduce the described issue, but to no avail. I am sending you a simple example, based on the mentioned demo. Please check it out and let me know what differs in your case.

Looking forward for your reply.

Kind regards,
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.

0
Jhess
Top achievements
Rank 1
answered on 02 Sep 2011, 07:50 AM
I have this problem for downloading pdf file.. see below details.

MTR_ShipersCode = char
error: Specified cast is not valid.
int attachmentId = (int)args.AttachmentKeyValues["MTR_ShipersCode"]

Hope you can help me with this.

Thank you,
Jhess

0
Radoslav
Telerik team
answered on 07 Sep 2011, 01:32 PM
Hi Jhess,

Based on the provided information is hard to say what is caused the described issue. Could you please post your aspx markup code with the related code behind or send us a sample where we could replicate the issue.  Thus we will be able to gather more details about your scenario and to provide you a solution.

Looking forward for your reply.

Regards,
Radoslav
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
M
Top achievements
Rank 1
answered on 24 Jul 2012, 04:40 PM
This example works great,
but my issue is that my files are located on the web server in a folder called 'files' (not in a table).
How do I make that work?

Thanks,
Mike
0
Radoslav
Telerik team
answered on 27 Jul 2012, 05:54 AM
Hello Mike,

When the files are located on the file system you could not use GridAttachmentColumn. In this case you could try adding a GridTemplateColumn with the asp:LinkButton (with set CommandName) into its ItemTemplate. Then when the LinkButton is clicked you could handle the RadGrid ItemCommand event, find pointed file into the file system and send it with the response. More information about how to download file you could find here:
http://www.daniweb.com/web-development/aspnet/threads/252778/file-download-in-asp.net-using-c-code
http://www.venkateswarlu.co.in/articles/DotNet/Download_File.aspx
http://codes.codedigest.com/CodeDigest/39-File-Download-in-ASP-Net-with-C-.aspx

I hope this helps.

All the best,
Radoslav
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
Radoslav
Telerik team
RvdGrint
Top achievements
Rank 1
Jhess
Top achievements
Rank 1
M
Top achievements
Rank 1
Share this question
or