现在我知道两种上传方法,但是这两种都没有办法加进度条,也无法获取是否上传成功
我现在用的是第一种方法,但是如果网络比较慢,文件比较大的时候会出现上传不成功的情况,而且没有异常,服务器上有此文件但是只有几KB,不知道是什么原因造成的
我本来想在第二种方法上加进度条,但是单步跟踪后发现,这种方法真正开始上传是在执行 postStream.Close()时 所以也无法加进度条
想找一种可以加进度条上传的方法 望指教
方法一
- VB code
Try Dim myWebClient As New WebClient myWebClient.UploadFile("http://192.168.1.201/2/1.zip", "put", "E:\psp\1\1.zip") Catch ex As Exception End Try
方法二
- VB code
Try Dim myWebClient As New WebClient Dim fs As FileStream = New FileStream("E:\psp\电影\rleis.zip", FileMode.Open, FileAccess.Read) Dim br As BinaryReader = New BinaryReader(fs) Dim uriString As Uri = New Uri("http://192.168.1.201/zdimp/rleis.zip") Dim postArray As Byte() = br.ReadBytes(CInt(fs.Length)) Dim postStream As Stream = myWebClient.OpenWrite(uriString, "PUT") If postStream.CanWrite Then postStream.Write(postArray, 0, postArray.Length) End If postStream.Close() Catch ex As Exception MsgBox(ex.ToString.Trim) End Try
------解决方案--------------------
友情帮顶
------解决方案--------------------
用ftp控件
------解决方案--------------------
可以搜一下大文件上传的代码。以前用过一个,是用httpmodule传的。
------解决方案--------------------
使用 WebClient 异步上载文件
带进度条
------解决方案--------------------
Upload.aspx是要加咋服务器上的。你要是演示,安装在本机就可以了。要给客户用,只要有iis运行asp.net环境就可以了