上传文件带进度条

   // 保存字节
                        using (FileStream fs = new FileStream(Path.Combine(path, fileName), FileMode.Create))
                        {                        
                            while (uploadInfo.UploadedLength < uploadInfo.ContentLength)
                            {
                               //从输入流放进缓冲区
                                int bytes = this.fileUpload.PostedFile.InputStream.Read(buffer, 0, bufferSize);
                                // 字节写入文件流
                                fs.Write(buffer, 0, bytes);
                                //  更新大小
                                uploadInfo.UploadedLength += bytes;

                                //  线程睡眠 上传就更慢 这样就可以看到进度条了
                                System.Threading.Thread.Sleep(100);
                            }
                        }

posted @ 2011-03-01 17:37  awp110  阅读(149)  评论(0编辑  收藏  举报