1

我正在使用 AsyncFileUpload 上传文件,在将文件保存在服务器上之前,我重命名了所选文件。如何在客户端获取这个新文件名?

<asp:AsyncFileUpload ID="AsyncFileUpload1" runat="server" 
                    OnUploadedComplete ="UploadFile1" 
                    OnClientUploadComplete="uploadComplete" ThrobberID="myThrobber" />

客户端脚本:

   <script>
   function uploadComplete(sender, args) {
         var fileExtension = args.get_fileName();
   }
   </script>

服务器端脚本:

Protected Sub UploadFile1(ByVal sender As Object, ByVal e As System.EventArgs)

    Dim fileuploadreceive1 As String = AsyncFileUpload1.PostedFile.FileName
    Dim strExtn As String = System.IO.Path.GetExtension(fileuploadreceive1).ToLower

    Dim filename1 As String = Path.GetFileName(fileuploadreceive1)
    filename1 = "uld" & Math.Round(Rnd() * 2366) & filename1 'changing original file name
    Dim fileuploadpath1 As String = Server.MapPath("~") & "\gallery\"

    If (strExtn = ".png") Or (strExtn = ".jpg") Or (strExtn = ".gif") Then
        AsyncFileUpload1.PostedFile.SaveAs(Path.Combine(fileuploadpath1, filename1))

    End If
End Sub
4

1 回答 1

0

你在谈论类似的事情:

<%= Page.ResolveClientUrl("~/images/MemoEditor_ABCtoolbar.png") %>

这将为它获取服务器名称,然后将其调用的内容传递给客户端。您可以将其包装在一些简单的 javascript 中,或者在此示例中,将其放在图像标签的 src 中。

var x = '<%= Page.ResolveClientUrl("~/images/MemoEditor_ABCtoolbar.png") %>';
于 2012-06-22T15:50:16.180 回答