如何在使用AsyncFileUpload时在clientside中重新命名serveride

服务器端码

protected void UploadComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e) { rlativepath =GeneratePrefixFileName() + AsyncFileUpload1.PostedFile.FileName; databasepath = "~/Image/" + rlativepath; filePath = Request.PhysicalApplicationPath + "image\\"+rlativepath; AsyncFileUpload1.SaveAs(filePath); } 

客户端代码

  function upLoadStarted() { $get("imgDisplay").style.display = "none"; } function showConfirmation(sender, args) { var txt = document.getElementById(''); var img = document.getElementById(''); txt.value = "Upload Successful"; var imgDisplay = $get("imgDisplay"); imgDisplay.src = "ajaxupload.jpg"; imgDisplay.style.cssText = "height:100px;width:100px"; var img = new Image(); img.onload = function () { imgDisplay.style.cssText = "height:100px;width:100px"; imgDisplay.src = img.src; };  img.src = ""+ args.get_fileName(); alert(img.src); var imagedescrip = $get("imagedescrip"); imagedescrip.style.cssText = "visibility:visible;"; } 

aspx页面:

   content of page FNever increase, beyond what is necessary, the number of entities required to explain anything." William of Ockham (1285-1349)     

我正在使用AsyncFileUpload上传文件,在将文件保存到服务器之前,我重命名了所选文件。 如何在客户端获取此新文件名? 现在我的问题是我没有在客户端使用args.get_filename()获取重命名文件名。如何获得它?

将HiddenField控件添加到窗体上:

  

重写UploadComplete方法如下:

 protected void UploadComplete(object sender, AsyncFileUploadEventArgs e) { var fileName = GeneratePrefixFileName() + System.IO.Path.GetFileName(e.FileName); var relativePath = "~/Image/" + fileName; var filePath = Server.MapPath(relativePath); AsyncFileUpload1.SaveAs(filePath); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "filePath", "top.$get(\"" + UploadedPathHiddenField.ClientID + "\").value = '" + ResolveClientUrl(relativePath) + "';", true); } 

之后,您可以通过以下方式获取showConfirmation方法中保存图像的路径:

 var src = $get("<%= UploadedPathHiddenField.ClientID %>").value;