一段显示下载进度条的下载文件代码
2008-01-07 08:12
471 查看
VB.NET
Public Shared Sub DownFile(ByVal URL As String, ByVal Filename As String, ByVal Prog As ProgressBar)
Dim Myrq As HttpWebRequest = HttpWebRequest.Create(URL)
Dim myrp As HttpWebResponse = Myrq.GetResponse
Dim totalBytes As Long = myrp.ContentLength
Prog.Maximum = totalBytes
Dim st As Stream = myrp.GetResponseStream
Dim so As Stream = New FileStream(Filename, FileMode.Create)
Dim totalDownloadedByte As Long = 0
Dim by(1024) As Byte
Dim osize As Integer = st.Read(by, 0, by.Length)
While osize > 0
totalDownloadedByte = osize + totalDownloadedByte
Application.DoEvents()
so.Write(by, 0, osize)
Prog.Value = totalDownloadedByte
osize = st.Read(by, 0, by.LongLength)
End While
so.Close()
st.Close()
End Sub
C#
public static void DownFile( string URL, string Filename, ProgressBar Prog )
{
System.Net.HttpWebRequest Myrq = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(URL);
System.Net.HttpWebResponse myrp = (System.Net.HttpWebResponse)Myrq.GetResponse();
long totalBytes = myrp.ContentLength;
Prog.Maximum = (int)totalBytes;
System.IO.Stream st = myrp.GetResponseStream();
System.IO.Stream so = new System.IO.FileStream(Filename, System.IO.FileMode.Create);
long totalDownloadedByte = 0;
byte[] by = new byte[1024];
int osize = st.Read(by, 0, (int)by.Length);
while (osize > 0)
{
totalDownloadedByte = osize + totalDownloadedByte;
Application.DoEvents();
so.Write(by, 0, osize);
Prog.Value = (int)totalDownloadedByte;
osize = st.Read(by, 0, (int)by.Length);
}
so.Close();
st.Close();
}
Public Shared Sub DownFile(ByVal URL As String, ByVal Filename As String, ByVal Prog As ProgressBar)
Dim Myrq As HttpWebRequest = HttpWebRequest.Create(URL)
Dim myrp As HttpWebResponse = Myrq.GetResponse
Dim totalBytes As Long = myrp.ContentLength
Prog.Maximum = totalBytes
Dim st As Stream = myrp.GetResponseStream
Dim so As Stream = New FileStream(Filename, FileMode.Create)
Dim totalDownloadedByte As Long = 0
Dim by(1024) As Byte
Dim osize As Integer = st.Read(by, 0, by.Length)
While osize > 0
totalDownloadedByte = osize + totalDownloadedByte
Application.DoEvents()
so.Write(by, 0, osize)
Prog.Value = totalDownloadedByte
osize = st.Read(by, 0, by.LongLength)
End While
so.Close()
st.Close()
End Sub
C#
public static void DownFile( string URL, string Filename, ProgressBar Prog )
{
System.Net.HttpWebRequest Myrq = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(URL);
System.Net.HttpWebResponse myrp = (System.Net.HttpWebResponse)Myrq.GetResponse();
long totalBytes = myrp.ContentLength;
Prog.Maximum = (int)totalBytes;
System.IO.Stream st = myrp.GetResponseStream();
System.IO.Stream so = new System.IO.FileStream(Filename, System.IO.FileMode.Create);
long totalDownloadedByte = 0;
byte[] by = new byte[1024];
int osize = st.Read(by, 0, (int)by.Length);
while (osize > 0)
{
totalDownloadedByte = osize + totalDownloadedByte;
Application.DoEvents();
so.Write(by, 0, osize);
Prog.Value = (int)totalDownloadedByte;
osize = st.Read(by, 0, (int)by.Length);
}
so.Close();
st.Close();
}
相关文章推荐
- 一段显示下载进度条的下载文件代码
- [导入]一段显示下载进度条的下载文件代码
- C# Winform下载文件并显示进度条的实现代码
- 一段读取文件时显示进度条的代码(CSDN上收录)
- 一段读取文件时显示进度条的代码(CSDN上收录)
- 显示下载进度条的下载文件代码
- 【CLI】利用Curl下载文件实时进度条显示的实现
- Delphi下载指定网址(URL)的文件,带进度条显示
- 用TreeView控件实现资源管理器(显示本地硬盘下所有文件夹和文件,并可以浏览图片)(示例代码下载)
- Control Study->AdRotator广告控件显示自定义配置文件中广告以及与DataGrid控件结合使用显示图片(示例代码下载)
- ios HTTP 文件下载 进度条显示
- php实现文件下载的一段代码
- 文件下载代码,可以用迅雷进行下载(因为之前用过一段下载文件的代码,但是不能用迅雷下载,超级汗!!!)
- 用进度条显示从网络上下载文件进度
- Android自带的下载功能,不需要断点续传、大文件下载、通知栏显示等窝心问题,四行代码全部搞定(经测)
- Android中带有进度条百分比显示的可以从网络下载文件的适配器
- 用TreeView控件实现资源管理器(显示本地硬盘下所有文件夹和文件,并可以浏览图片)(示例代码下载)
- 利用curl下载文件(进度条显示) 代码片段
- wget下载文件时进度条后面显示英国中部时间eta(Estimated Time of Arrival 预计到达时间)解决办法
- 关于apache上的CGI文件问题总结--为什么无法找到cgi文件、为什么找到了cgi文件却不执行反而询问是否下载或直接显示文件代码