File upload status

B

Brian Henry

I am uploading a file from the file input box (textbox with a browse button)
but when you tell the file to upload the client doesn't see anything happen
until its done uploading... I'd love to provide some kind of visual feedback
(an animated image or something while it happens to show its going, and at
best a progress of the upload) is there anyway to do this in asp.net? thanks
 
W

Weston Weems

There are several different implementations in asp.net

One being the creation of custom handlers or custom content handlers, I dont
recall which. It would provide REAL per byte upload status etc.

Others just simply provide an estimation on the fly.

Check out www.codeproject.com, where there is an article on file upload
status, and in the comments, a link to the real nice one.


Weston Weems
 
S

Steven Cheng[MSFT]

Thanks for Weston's informative suggestions.

Hi Brian,

Generaly we can use javascript function to display some waiting message on
the page when there is a long run task being processed at the serverside
when the page is posted back. Here is a simple demo page:

============aspx page===============
<HTML>
<HEAD>
<title>showwaitmsg</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript">
function initialProgress()
{
document.getElementById("divProgress").innerText = "Uploading...";
window.setInterval("addDots();",500);
}

function addDots()
{
document.getElementById("divProgress").innerText =
document.getElementById("divProgress").innerText + ".";
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="100%" align="center">
<tr>
<td><INPUT id="fpMain" type="file" name="File1" runat="server">
<asp:Button id="btnUpload" runat="server" Text="Upload"></asp:Button>
</td>
</tr>
<tr>
<td>
<div id="divProgress" />
</td>
</tr>
</table>
</form>
</body>
</HTML>


==========code behind================
public class showwaitmsg : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button btnUpload;
protected System.Web.UI.HtmlControls.HtmlInputFile fpMain;

private void Page_Load(object sender, System.EventArgs e)
{
btnUpload.Attributes.Add("onclick","initialProgress();");
}

#region Web
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{
this.btnUpload.Click += new System.EventHandler(this.btnUpload_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void btnUpload_Click(object sender, System.EventArgs e)
{
try
{
if(fpMain.PostedFile != null)
{
string filename =
System.IO.Path.GetFileName(fpMain.PostedFile.FileName);
Response.Write("<br>" + filename + " is uploaded!");
System.Threading.Thread.Sleep(3* 1000);
}
}
catch(Exception ex)
{
Response.Write("<br>" + ex.Message);
}
}
}
=========================================

In addition, here are some other tech articles discussing the similar
topics:

#How to show progress in the client browser for a long-running ASP.NET page
http://support.microsoft.com/?id=837375

#DESIGN PATTERNS: Asynchronous Wait State Pattern in ASP.NET
http://msdn.microsoft.com/msdnmag/issues/03/12/designpatterns/default.aspx
http://www.aspnetpro.com/NewsletterArticle/2003/08/asp200308bm_l/asp200308bm
_l.asp

Hope also helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top