file download functionality

8 posts, 0 answers
  1. mww
    mww avatar
    257 posts
    Member since:
    Sep 2012

    Posted 06 Feb 2011 Link to this post

    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 ?
  2. Radoslav
    Admin
    Radoslav avatar
    1564 posts

    Posted 09 Feb 2011 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. RvdGrint
    RvdGrint avatar
    112 posts
    Member since:
    May 2011

    Posted 30 May 2011 Link to this post

    Radoslav,

    I've the same problem with a GridAttachmentColumn. I've 'copied' the example you mentioned but still keep the c00ce514 error.
  5. Radoslav
    Admin
    Radoslav avatar
    1564 posts

    Posted 02 Jun 2011 Link to this post

    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.

  6. Jhess
    Jhess avatar
    4 posts
    Member since:
    Aug 2011

    Posted 02 Sep 2011 Link to this post

    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

  7. Radoslav
    Admin
    Radoslav avatar
    1564 posts

    Posted 07 Sep 2011 Link to this post

    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 >>

  8. M
    M avatar
    24 posts
    Member since:
    Jul 2012

    Posted 24 Jul 2012 Link to this post

    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
  9. Radoslav
    Admin
    Radoslav avatar
    1564 posts

    Posted 27 Jul 2012 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017