AsyncFileUpload AJAX Control

//.aspx Code:
<head runat=”server”>
<title>::AsyncFileUpload::</title>
<script type=”text/javascript” language=”javascript”>
function uploadError(sender, args) {
document.getElementById(‘lblStatus’).innerText = args.get_fileName(),
“<span style=’color:red;’>” + args.get_errorMessage() + “</span>”;
}
function StartUpload(sender, args) {
document.getElementById(‘lblStatus’).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’).innerText = text;
}
</script>
</head>
<body>
<form id=”form1″ runat=”server”>
<asp:ScriptManager ID=”ScriptManager1″ runat=”server”></asp:ScriptManager>
<div>
<asp:AsyncFileUpload ID=”AsyncFileUpload1″ Width=”400px” runat=”server” OnClientUploadError=”uploadError” OnClientUploadStarted=”StartUpload” OnClientUploadComplete=”UploadComplete” CompleteBackColor=”Lime” UploaderStyle=”Modern” ErrorBackColor=”Red” ThrobberID=”Throbber” onuploadedcomplete=”AsyncFileUpload1_UploadedComplete” UploadingBackColor=”#66CCFF” />
<asp:Label ID=”Throbber” runat=”server” Style=”display: none”><img src=”ajax-loader.gif” align=”absmiddle” alt=”loading” /></asp:Label>
<asp:Label ID=”lblStatus” runat=”server” Style=”font-family: Arial;  font-size: small;”></asp:Label>
</div>
</form>
</body>
//.cs Code
protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
System.Threading.Thread.Sleep(5000);
if (AsyncFileUpload1.HasFile)
{
string strPath = MapPath(“~/Uploads/”) + (e.filename.Substring(e.filename.LastIndexOf(‘\\’)+1));
AsyncFileUpload1.SaveAs(strPath);
}
}

Comments

Popular posts from this blog

Specify port number in ASP.NET Development Server

Server Variables in .Net Web Application

Free Windows Azure Exam