Getting a new file name saved with ajax AsyncFileUpload?

I save the file with the asyncfileupload ajax plugin from ajax toolkit, and when I save it, I change the file name (to avoid multiple files with the same name).

After downloading the file, the user should know which file was named, so I use this javascript code in the onclientuploadcomplete event.

function UploadComplete(sender, args) { alert(args.get_fileName()); } 

This works, except that it gets the old name, not the new name (which is defined on the server side). Is there a way to get him to return the new name, not the old name? Or any work around this?

This is my code in the code for the new file name:

 string filename = DateTime.Now.ToString("dMyHmsf") + e.filename; string strPath = MapPath("~/SavedImages/") + filename; AsyncFileUpload1.SaveAs(strPath); 
+4
source share
2 answers

I got a response from http://forums.asp.net/post/4139037.aspx It works for me ...

copied code from there:

 <asp:ToolkitScriptManager runat="server"> </asp:ToolkitScriptManager> <!--This script snippet must be located below the ScriptManager--> <script type="text/javascript"> Sys.Extended.UI.AsyncFileUpload.prototype.newFileName = null; //I did not use this line function uploadcomplete(sender, e) { alert(sender.newFileName); } </script> <asp:AsyncFileUpload ID="AsyncFileUpload1" OnClientUploadComplete="uploadcomplete" runat="server" OnUploadedComplete="AsyncFileUpload1_UploadedComplete1" /> 

code behind:

 protected void AsyncFileUpload1_UploadedComplete1(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "newfile", "window.parent.$find('" + AsyncFileUpload1.ClientID + "').newFileName='newfile.jpg';", true); } 
+3
source

How about writing the file name in a hidden field in the code and reading that value in your client code?

+1
source

Source: https://habr.com/ru/post/1332425/


All Articles