Download Link

5 posts, 0 answers
  1. Matthew
    Matthew avatar
    51 posts
    Member since:
    Oct 2012

    Posted 11 Jul 2013 Link to this post

    I'm trying to set up a download link button, but it seems impossible. I keep getting the following error:

    InnerException: Cannot convert object of type 'System.Int32' to type 'System.Collections.IDictionary'

    FileName:
    FileLineNumber: 0
    FileColumnNumber: 0
    Method
    : System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal
    StackTrace
    :
    Message: DotNetNuke.Services.Exceptions.PageLoadException: Cannot convert object of type 'System.Int32' to type 'System.Collections.IDictionary' ---> System.InvalidOperationException: Cannot convert object of type 'System.Int32' to type 'System.Collections.IDictionary' at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject) at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject) at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String input) at Telerik.Web.UI.GridCommandEventArgsFactory.CreateGridCommandEventArgs(GridItem item, Object commandSource, CommandEventArgs originalArgs) at Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e) at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) --- End of inner exception stack trace ---

    This is from DotNetNuke's Log Viewer. I have a user control with a RadGrid that contains the RadButton(s) I'm using to make the download links. This control is loaded in various places that wrap the control with an RadAjaxPanel. Even when I switch it to a Panel ajaxified by a RadAjaxManager this issue appears. What does this error mean? I have no means of debugging it.
  2. Matthew
    Matthew avatar
    51 posts
    Member since:
    Oct 2012

    Posted 11 Jul 2013 Link to this post

    I'd like it if this went through the RadGrid, but for now I'm using buttons like this:

    <telerik:RadButton runat="server" AutoPostBack="true" ButtonType="LinkButton" CausesValidation="false"
    CommandName='<%# RadGrid.DownloadAttachmentCommandName %>' CommandArgument='<%# Eval("FileID") %>'
    OnLoad="rbDownload_Load" OnCommand="Download_Command" Skin="" Text='<%# Eval("FileName") %>' />

    protected void rbDownload_Load(object sender, EventArgs e)
    {
        RadButton rb = sender as RadButton;
        ScriptManager.GetCurrent(Page).RegisterPostBackControl(rb);
    }
     
    protected void Download_Command(object sender, CommandEventArgs e)
    {
        using (MyDataContext dbContext = new MyDataContext())
        {
            File file = dbContext.Files.Single(f => f.FileID == Convert.ToInt32(e.CommandArgument));
            Response.Clear();
            Response.ContentType = System.Net.Mime.MediaTypeNames.Application.Octet.ToString();
            Response.AppendHeader("Content-Disposition", String.Format("attachment; filename={0}", file.FileName));
            Response.BinaryWrite(file.FileData.ToArray());
            Response.End();
        }
    }
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1803 posts

    Posted 16 Jul 2013 Link to this post

    Hello Matthew,

    Thank you for contacting us.

    This exception is thrown due to the fact that you are setting CommandArgument to be System.Int32 type, but DownloadAttachment command uses System.Collections.IDictionary type. FireCommandEvent with DownloadAttachment command have the following syntax:
    FireCommandEvent("DownloadAttachment", GridDownloadAttachmentCommandEventArgs)

    Please take a look at our help article "RadGrid Column Types" and see the description for GridAttachmentColumn. There you will find how to properly set GridDownloadAttackmentCommandEventArgs and fire DownloadAttachment command. 

    You could also see our online demo for the GridAttachmentColumn.

    If you continue to experience difficulties, please feel free to get back to us.

    Regards,
    Konstantin Dikov
    Telerik
    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 the blog feed now.
  5. Tawab
    Tawab avatar
    5 posts
    Member since:
    Jun 2011

    Posted 09 May in reply to Konstantin Dikov Link to this post

    I was getting the exception above, but for a different reason.  It was because I had set the CommandName property on my GridButtonColumn to "DownloadAttachment".  If I set it to "DownloadFile", everything works fine.  It is as if "DownloadAttachment" is some sort of keyword reserved by Telerik, causing the GridButtonColumn to be interpreted as a GridAttachmentColumn.  It took several hours of banging my head to figure this out, so I post it in case it helps someone.
  6. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1803 posts

    Posted 12 May Link to this post

    Hello Tawab,

    In the following help article you will find the command names used by RadGrid:
    As you will notice, DownloadAttachment is one of them, so it was initiating the built-in command in your scenario.



    Kind Regards,
    Konstantin Dikov
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017