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

Download Link

4 Answers 130 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Matthew
Top achievements
Rank 1
Matthew asked on 11 Jul 2013, 06:51 PM
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.

4 Answers, 1 is accepted

Sort by
0
Matthew
Top achievements
Rank 1
answered on 11 Jul 2013, 07:50 PM
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();
    }
}
0
Konstantin Dikov
Telerik team
answered on 16 Jul 2013, 11:43 AM
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.
0
Tawab
Top achievements
Rank 1
answered on 10 May 2016, 03:12 AM
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.
0
Konstantin Dikov
Telerik team
answered on 12 May 2016, 11:26 AM
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.
Tags
Ajax
Asked by
Matthew
Top achievements
Rank 1
Answers by
Matthew
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Tawab
Top achievements
Rank 1
Share this question
or