Monday, August 6, 2012

Unhandled Exception: "The file attached is invalid" with AsyncFileUploader and .NET Framework 4

 

I upgraded my ASP.NET framework from 3.5 to 4 recently, and encountered a host of problems.

I knew the problem was due to the upgrade because I had not changed my code, and yet, there were parts of the system that went haywire with seemingly esoteric errors.

Today, I got the error below when I tried to upload images on a web page that was working perfectly before.

2012-08-06_102203

 

Fortunately, the error is easy to solve.  I just followed the tip from ndkjava given on the ASP.NET forum.

Basically, what you need to do is to locate the control on the markup code and add this attribute to it.

ClientIDMode="AutoID"

For example, this is how my code looks like after adding it.

<asp:AsyncFileUpload ClientIDMode="AutoID" ID="AsyncFileUpload1" runat="server"  onuploadedcomplete="AsyncFileUpload1_UploadedComplete" />

Everything seems to work marvellously after that! :)


ps. If you want to download the latest version of the FileAsyncUpload which is in the ASP.NET AJAX Control Toolkit 4, you can get it at CodePlex here (updated 24 Jun 2012).


For tutorials on how to use the AJAX Control Toolkit FileAsyncUpload control,  you can find one here.

No comments: