最近我研究了一下怎样实现 绑定 数据上传过程中的真实进度问题我自己有个上传方法,其中采用的不是直接saveas(),
而是采用了byte数据流的方式,代码如下:
string uploadPath = Server.MapPath("Ebook\\" + ebookname);//上传路径 FileStream fs = new FileStream(uploadPath, FileMode.Create); BinaryWriter bw = new BinaryWriter(fs); byte[] buffer = new Byte[10000]; while (contentLength > 0)
{
// Read the data in buffer.
int length = FileUpload1.PostedFile.InputStream.Read(buffer, 0, 10000);
// Write the data to the current output stream.
bw.Write(buffer, 0, length); buffer = new Byte[10000]; contentLength = contentLength - length;
/////////////label.text=contentLength ;
} fs.Close(); bw.Close();
请仔细看,这个方法实际上是放在了一个委托方法内的,通过按扭的点击来触发委托事件、
delegate void ShowProgressDelegate();ShowProgressDelegate showProgress = new ShowProgressDelegate(Progress);showProgress.Invoke();一开始的时候本来我是想用backgroundworker类的异步方式来显示进度,就是在红色部分的label内显示字节数;可是执行的时候,出错,显示,不是ui线程不可以调用此线程以外的ui线程内的控件所以我通过查找资料,知道,可以把所有由线程(无论是什么线程)来完成的任务交给委托,所以我采用了上边的方式可是依然没效果,就是说,只要是在while循环内,窗体上的label上就不能象winform程序一样时时刷新进度,后来我想,是不是页面刷新问题呢?所以我有在label外套了一个updatepanel,可是,还是不行。
请大神帮帮忙拉,我就是想时时显示进度(是真实进度),小弟不常来上网,分比较少,请多多担待,谢谢
而是采用了byte数据流的方式,代码如下:
string uploadPath = Server.MapPath("Ebook\\" + ebookname);//上传路径 FileStream fs = new FileStream(uploadPath, FileMode.Create); BinaryWriter bw = new BinaryWriter(fs); byte[] buffer = new Byte[10000]; while (contentLength > 0)
{
// Read the data in buffer.
int length = FileUpload1.PostedFile.InputStream.Read(buffer, 0, 10000);
// Write the data to the current output stream.
bw.Write(buffer, 0, length); buffer = new Byte[10000]; contentLength = contentLength - length;
/////////////label.text=contentLength ;
} fs.Close(); bw.Close();
请仔细看,这个方法实际上是放在了一个委托方法内的,通过按扭的点击来触发委托事件、
delegate void ShowProgressDelegate();ShowProgressDelegate showProgress = new ShowProgressDelegate(Progress);showProgress.Invoke();一开始的时候本来我是想用backgroundworker类的异步方式来显示进度,就是在红色部分的label内显示字节数;可是执行的时候,出错,显示,不是ui线程不可以调用此线程以外的ui线程内的控件所以我通过查找资料,知道,可以把所有由线程(无论是什么线程)来完成的任务交给委托,所以我采用了上边的方式可是依然没效果,就是说,只要是在while循环内,窗体上的label上就不能象winform程序一样时时刷新进度,后来我想,是不是页面刷新问题呢?所以我有在label外套了一个updatepanel,可是,还是不行。
请大神帮帮忙拉,我就是想时时显示进度(是真实进度),小弟不常来上网,分比较少,请多多担待,谢谢
解决方案 »
- asp.net MVC3 找不到请求的.Net framework data provider
- asp.net Mvc 3循环table 问题 。
- Asp.net—SQL server好书
- 连接数据库的问题!
- 把一个集合(或其它东东)转化为实体类的方式
- 我查询出来的一张表,显示在DataGrid中,我想把它保存在一张表里面,待下次查询的时候直接调这个表里面的东西,怎么实现啊?
- Asp.Net优化问题:CPU占用率100%,内存只用了30-40%。(一)
- ((DataGrid)source).CurrentPageIndex = e.NewPageIndex 前面怎么理解?
- 这是啥意思?无法找到脚本库“/aspnet_client/system_web/1_1_4322/webuivalidation.js“。请尝试手动放置此文件
- datagridView中的DataGridViewCheckBoxColumn问题
- 怎么将SQL查询的数据表里的数据绑定到GridView上啊???
- vs2005中如何验证一个textbox中必须是数字?
Application.Doevents;