如何在C#asp.net中在运行时显示文件上传进度 [英] How to show file upload progress at run time in c# asp.net

查看:62
本文介绍了如何在C#asp.net中在运行时显示文件上传进度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个文件对话框控件,通过它可以选择多个文件,然后单击一个名为upload的按钮.读取文件将验证该文件并将其转储到数据库中.循环查找下一个文件并执行相同的步骤顺序.

现在,我希望标签显示类似
的状态 1/3个文件正在上传..
等等..

如何在运行时更改标签文本?

注意:我正在使用IE7.因此不能使用ajax文件上传控件.

下面的示例代码:

Hi All,

I have a file dialog control through which i select multiple files and click a button called upload.which reads the file validates and dumps it into the database.Loops through for the next file and does the same sequence of steps.

Now i want a label to show the status like
1/3 files uploading ..
and so on..

How to i change the label text on run time?

Note: I am working on IE7. so cannot use ajax file upload control.

sample code below:

public void upload files(string[] arrayoffilenames)
{
int intfileLoadcount=0;

foreach ( filename in arrayofFilenames)
{
intfileLoadCount = intfileLoadcount + 1;
--here i want to display like 1/5 files loading 
//Read file
//Write file to database
--here i want to display like 1/5 files loading completed
}
}

推荐答案

您正在使用服务器端代码上传回发文件.因此,尽管您在循环中具有控件,但是在标签中分配计数器将不会显示所做的更改,直到整个操作完成并且页面已完全加载.

因此,您需要可以与客户端进行交互的东西.因此,Ajax是应对这种情况的首选.

看看这个链接,
简单的AJAX文件上传 [
You are using server side code to upload files in postback. So, though you have controls within the loop, assigning a counter in a label will not display the changes until the whole operation done and the page is fully loaded.

So, you need something which you can interact from client side. So, Ajax is the first choice to cope up with this scenario.

Have a look to this link,
Simple AJAX File Upload[^]

Hope this clears your confusion.
cheers


访问给定的URL肯定会有所帮助...

简单的AJAX文件上传 [
Visit given URL it will help surely...

Simple AJAX File Upload[^]


< a href ="< a href ="></a> [< a href =" target ="_ blank"></a>]></a>
<a href="<a href=""></a>[<a href="" target="_blank"></a>]"></a>
<pre lang="Javascript"><pre lang="SQL"><pre lang="SQL">


这篇关于如何在C#asp.net中在运行时显示文件上传进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆