多文件上传的进度条 [英] Progressbar for Multifile upload

查看:116
本文介绍了多文件上传的进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我是这个讨论板的新手.
多个文件的进度条出现问题.我已经使用treeview开发了一个多文件上传器.现在,我需要显示上传进度,为此,我需要从服务器端函数中执行上传的JavaScript函数调用(我尝试了RegisterClientScriptBlock但没有用),并且该函数应该在上传时更新进度栏正在后端进行处理

请提供一些解决方法的帮助,以帮助我?

谢谢,
NM

Hi,

I am new to this discussion board.
I have a problem with progressbar for multiple file upload. I have developed a multiple file uploader using treeview. now i need to show the progress of the upload, for which i need to call a javascript function from server side function which does the upload ( I tried RegisterClientScriptBlock but didn''t work) and this function should update the progress bar while the upload process is being done on backend

please help me by giving some idea of how this can be solved?

Thanks,
NM

推荐答案

我在一个codeproject博客本身中找到了一个很好的解决方案
http://www.aspnettutorials.com/tutorials/themes/progress-bar-csharp.aspx

它实际上是在文件上传过程中使用线程,但问题是它没有使用最终结果(例如上传过程所花费的时间)来更新页面

根据我的要求,我将progressbar.aspx页放在上载"页上的iframe中,并尝试在Progressbar.aspx页中调用一个函数,该函数随后将调用javascript来更新window-submit,该JavaScript会不时更新进度时间.

还要计算上传完成的百分比,我们计算了所有文件的大小,并计算了当前文件大小在整个大小中的百分比

停止线程并更新页面,这是我们添加的代码

catch(ex ex例外)
{
LogText(& quot;异常:& quot;例如ex.Message);
if(ex.InnerException!= null)LogText(& quot;内部异常:& quot; ex.InnerException.Message);
LogListToSession();
会话[&状态&"] = 100;
Page.RegisterClientScriptBlock(& lt; script& lt; script& gt; window.close(&#39; Progress.aspx&#39;);</script& gt;& quot));
}</pre>

这是打开进度条

公共静态无效OpenProgressBar(System.Web.UI.Page Page)
{
试试
{
ProgressBar_C_.Progress Prgbar =新的ProgressBar_C_.Progress();
Prgbar.CallProgress();
}
catch(ex ex例外)
{
}

获取所有选择上传的文件的长度


受保护的void GetLengthofAllFiles(string [] filesToBeUploaded)
{
foreach(filesToBeUploaded中的字符串文件)
{
//获取文件长度并将其添加到totalLength
System.IO.FileInfo fileInfo =新的System.IO.FileInfo(文件);
totalLength = totalLength + fileInfo.Length;
}

}
I found a good solution in one of the codeproject blogs itself
http://www.aspnettutorials.com/tutorials/themes/progress-bar-csharp.aspx

it actually is using a threading for the file upload process but the problem was that it is not updating the page with final results like time taken for the upload process

for my requirement i placed the progressbar.aspx page in an Iframe on my Upload page and tried to call a function in Progressbar.aspx page which inturn will call window.submit using javascript that is updating the progress time to time

also to calculate the percentage of upload done we took the size of all the files and calculated the percentage of current file size in the whole size

to stop the thread and update the page this is the code we added

catch (Exception ex)
{
LogText(&quot;Exception : &quot; + ex.Message);
if (ex.InnerException != null) LogText(&quot;Inner Exception : &quot; + ex.InnerException.Message);
LogListToSession();
Session[&quot;State&quot;] = 100;
Page.RegisterClientScriptBlock(&quot;&quot;, &quot;&lt;script&gt;window.close(&#39;Progress.aspx&#39;);&lt;/script&gt;&quot;);
}</pre>

this is to open the progressbar

public static void OpenProgressBar(System.Web.UI.Page Page)
{
try
{
ProgressBar_C_.Progress Prgbar = new ProgressBar_C_.Progress();
Prgbar.CallProgress();
}
catch (Exception ex)
{
}

to get length of all the files selected to upload


protected void GetLengthofAllFiles(string[] filesToBeUploaded)
{
foreach (string file in filesToBeUploaded)
{
//get and add the file length to totalLength
System.IO.FileInfo fileInfo = new System.IO.FileInfo(file);
totalLength = totalLength + fileInfo.Length;
}

}


这篇关于多文件上传的进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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