Protected Sub AsyncFileUpload1_UploadedComplete(ByVal sender As Object, ByVal e As AjaxControlToolkit.AsyncFileUploadEventArgs)
System.Threading.Thread.Sleep(5000)
If AsyncFileUpload1.HasFile Then
strPath = Server.MapPath("~\Uploads\" & AsyncFileUpload1.FileName)
AsyncFileUpload1.SaveAs(strPath)
'ScriptManager.RegisterClientScriptBlock(Me.Page, Me.GetType, "Error", "<script language=javascript>alert('" & strPath.Replace("\", "\\") & "');</script>", False)
End If
lblPath.text = strPath
End Sub
Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Partial Class ContractAdd
Inherits System.Web.UI.Page
Dim dr As SqlDataReader
Dim strFID As String = Date.Today.Year
Dim strNetID As String
Dim chkMPeriod As String
Dim strContrID As Integer = 0
Dim strPreSubContrID As String = ""
Dim strSubContrID As String = ""
Dim YearContr As String = DateTime.Now.Year.ToString
Dim strAutoContrID As String = ""
Dim strPath As String
Protected Sub AsyncFileUpload1_UploadedComplete(ByVal sender As Object, ByVal e As AjaxControlToolkit.AsyncFileUploadEventArgs)
System.Threading.Thread.Sleep(5000)
If AsyncFileUpload1.HasFile Then
strPath = Server.MapPath("~\Uploads\" & AsyncFileUpload1.FileName)
AsyncFileUpload1.SaveAs(strPath)
'strPath = Server.MapPath("Uploads/" & AsyncFileUpload1.FileName)
'txtRetention.Text = strPath.Replace("\", "\\")
'ScriptManager.RegisterClientScriptBlock(Me.Page, Me.GetType, "Error", "<script language=javascript>alert('" & strPath.Replace("\", "\\") & "');</script>", False)
End If
Session("Path") = strPath
Label1.Text = strPath
End Sub
End Class
อันล่างนี้เป็น script ที่ใช้อ่ะกับ AsyncFileUpload ใช้แค่สองอย่างนี้แหละครับ
function StartUpload(sender,args)
{
document.getElementById('<%=lblStatus.ClientID%>').innerText = 'Uploading Started.';
}
function UploadComplete(sender,args)
{
var filename = args.get_fileName();
var contentType = args.get_contentType();
var text = "Size of " + filename + " is " + args.get_length() + " bytes";
if (contentType.length > 0)
{
text += " and content type is '" + contentType + "'.";
}
document.getElementById('<%=lblStatus.ClientID%>').innerText = text;