I'm trying to use the new AjaxFileUpload in the control toolkit.
Everything "appears" to be working.... as in I get no errors in my code, the event fires, and the aspx.page shows the uploads and completes, but none of the files ever save.
It looks so simple yet I just cant seem to get the file to save to a folder on the development machine...
Check to make sure that they are saving to the right location. Your code for your path variable might be throwing it off, meaning MapPath("~/tmp/") might be returning something like... "C:\YourCoolFolder" and then you are immediately appending the file name
so it migh tbe like...
"C:\YourCoolFolderYourCoolPicture.jpg" so it might be missing a backslash ("\") there.
You can also put that in a try/catch block to see whats going on if its throwing a possible error.
It seemed my file path was not correct. The confusing part was that I was not using a try/catch, yet the page would report the upload as successful when it obviously wasnt.
scheffetz
Member
12 Points
50 Posts
AjaxFileUpload file not saving
May 22, 2012 04:09 PM|LINK
I'm trying to use the new AjaxFileUpload in the control toolkit.
Everything "appears" to be working.... as in I get no errors in my code, the event fires, and the aspx.page shows the uploads and completes, but none of the files ever save.
It looks so simple yet I just cant seem to get the file to save to a folder on the development machine...
protected void UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e) { string path = MapPath("~/tmp/") + e.FileName; AjaxFileUpload1.SaveAs(path); }<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <ajaxToolkit:ToolkitScriptManager runat="server"> </ajaxToolkit:ToolkitScriptManager> <ajaxToolkit:AjaxFileUpload ID="AjaxFileUpload1" runat="server" ThrobberID="MyThrobber" OnUploadComplete="UploadComplete" /> <asp:Image ID="myThrobber" runat="server" ImageUrl="~/Images/throbber.gif" Style="display:None" /> </asp:Content>teh munk
Participant
1466 Points
297 Posts
Re: AjaxFileUpload file not saving
May 22, 2012 04:13 PM|LINK
Does the tmp directory exist and have the correct folder permissions?
N_EvilScott
Star
8179 Points
1466 Posts
Re: AjaxFileUpload file not saving
May 22, 2012 04:17 PM|LINK
Check to make sure that they are saving to the right location. Your code for your path variable might be throwing it off, meaning MapPath("~/tmp/") might be returning something like... "C:\YourCoolFolder" and then you are immediately appending the file name so it migh tbe like...
"C:\YourCoolFolderYourCoolPicture.jpg" so it might be missing a backslash ("\") there.
You can also put that in a try/catch block to see whats going on if its throwing a possible error.
protected void UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e) { try { string path = MapPath("~/tmp/") + e.FileName; AjaxFileUpload1.SaveAs(path); } catch (Exception ex) { // grab exception here. } }Nasser Malik
Star
11292 Points
1737 Posts
Re: AjaxFileUpload file not saving
May 22, 2012 04:21 PM|LINK
Skype: maleknasser1
chetan.sarod...
All-Star
65749 Points
11148 Posts
Re: AjaxFileUpload file not saving
May 23, 2012 03:29 AM|LINK
Refer this
http://stephenwalther.com/blog/archive/2012/05/01/ajax-control-toolkit-may-2012-release.aspx
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/AjaxFileUpload/AjaxFileUpload.aspx
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.
scheffetz
Member
12 Points
50 Posts
Re: AjaxFileUpload file not saving
May 23, 2012 09:15 AM|LINK
It seemed my file path was not correct. The confusing part was that I was not using a try/catch, yet the page would report the upload as successful when it obviously wasnt.
In the end, this is what worked for me....
protected void UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e) { string c = System.IO.Path.GetFileName(e.FileName); string path = MapPath("//c:/tmp/") + c; AjaxFileUpload1.SaveAs(path); SetLabel(c); }