Reputation: 321
I'm trying to implement a simple ajaxtoolkit fileupload control and every time I click "Upload" all I get is an error. I tried placing breakpoint in the "AjaxFileUpload1_UploadComplete" function but it won't even get fired.. (maybe because upload isn't complete yet?) what should I do to make it work?
here is the error:
here is my aspx:
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server"
onuploadcomplete="AjaxFileUpload1_UploadComplete" ThrobberID="myThrobber" MaximumNumberOfFiles="10" AllowedFileTypes="jpg,jpeg"/>
</div>
</form>
and here is the funcion behind:
protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
string id = "038191904";
Directory.CreateDirectory(Server.MapPath("~/App_Data/" + id + "/scanned_docs/"));
string filePath = "~/Member_Data/" + id + "/images/";
string path = filePath + e.FileName;
AjaxFileUpload1.SaveAs(Server.MapPath(filePath) + e.FileName);
//db1.insert_pic_slide(id, path);
}
Upvotes: 14
Views: 20781
Reputation: 150
Just going to add this troubleshooting advice for the AjaxFileUpload control. If you added all of the web.config statements as recommended on this page and still get an error on upload, swap out the AjaxFileUpload control with the Ajax AsyncFileUpload control. The code between the two are almost identical to use and it will only take a minute to swap them out.
The AjaxFileUpload captures errors and it is very hard to find the real reason of the upload problem. The AsyncFileUpload will throw the actual error.
I spent a whole afternoon digging through forums on the AjaxFileUpload for what looked like a directory permissions/temp folder issue. I actually had a database error that I was able to fix 15 minutes after I swapped to the AsyncFileUpload and ran into the real problem.
The error that the AjaxFileUpload was throwing when I debugged in FireFox was:
ajaxfileupload error raising upload complete event and start new upload
And the IIS error was error 500.
Keep in mind it was just a database error. I added a column locally that I forgot to add to the hosting database, so it worked locally for me, but threw an error on the hosting server when I deployed.
Close to a whole day of work on something that should have taken 15 minutes to fix.
Upvotes: 0
Reputation: 648
This was happening to me, and I did two things to fix it:
1) Update your site's web.config file to contain entries for the following:
<system.web>
<httpHandlers>
<add verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit" />
</httpHandlers>
</system.web>
<system.webServer>
<handlers>
<add name="AjaxFileUploadHandler" verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit" />
</handlers>
</system.webServer>
2) If the page you're uploading from is inside a folder with it's own web.config with deny anonymous authorization rules, make sure you add an allow for the AjaxFileUploadHandler like so:
<location path="AjaxFileUploadHandler.axd">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
Upvotes: 29