[英]Is it possible to show progress/ update bar while writing files usinfg FileStream
im working on a web application that reads files from some where and writes it down on the disk using System.IO.FileStream
class. 我在一个Web应用程序上工作,该Web应用程序从某些位置读取文件,然后使用
System.IO.FileStream
类将其写到磁盘上。 Is it possible to display some kind of progress bar or update bar while i write these files. 我写这些文件时是否可以显示某种进度条或更新条。
Here is sample code 这是示例代码
using (Stream input = getResponse.GetResponseStream())
{
using (FileStream output = new FileStream(saveTo1, FileMode.OpenOrCreate))
{
int bytesRead;
while ((bytesRead = input.Read(buffer, 0, buffer.Length))>0)
{
output.Write(buffer, 0, bytesRead);
}
}
}
Thanks in advance. 提前致谢。 :)
:)
Try using Update Progress. 尝试使用更新进度。
What you need to do? 你需要做什么?
Please change the image name to whatever image you have in the following lines of code 请在以下代码行中将图像名称更改为您拥有的任何图像
<asp:UpdateProgress ID="updateProgress" runat="server" DisplayAfter="0" AssociatedUpdatePanelID="UPanelOperation"> <ProgressTemplate> <div id="progressBackgroundFilter"> </div> <div align="center"> <img src="../../css/images/1-0.gif" /> Please Wait...</div> </ProgressTemplate> </asp:UpdateProgress>
Of course you can. 当然可以。 Edit your code as follows:
如下编辑代码:
while ((bytesRead = input.Read(buffer, 0, buffer.Length))>0)
{
label1.Text = buffer.ToString() + " bytes transfered.";
output.Write(buffer, 0, bytesRead);
}
...where label1 is a control you place on the form. ...其中label1是您放置在表单上的控件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.