2012-06-22 76 views
1

我在使用AsyncFileUpload上傳文件之前,先保存服務器上的文件,然後重命名所選文件。我怎樣才能在客戶端獲得這個新的文件名?如何在客戶端使用AsyncFileUpload獲取serverside文件名

<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 

回答

0

是你講的東西,如:

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

這將讓服務器爲它命名,然後傳遞它的名字給客戶打電話。你可以用一些簡單的javascript包裝它,或者在這個例子中,把它放在圖片標籤的src中。

var x = '<%= Page.ResolveClientUrl("~/images/MemoEditor_ABCtoolbar.png") %>'; 
+1

我在說'args.get_fileName();'它返回原來的'filename1' – Maysam

相關問題