不错呦!smile@林凯西,确保“准备文件”中的几个文件都有安装,S...您好,看了您这篇帖子觉得很有帮助。但是有个问题想请...我的修改过了怎么还被恶意注册呢 @jjjjiiii 用PJ快9年了,主要是A...PJ3啊,貌似很少有人用PJ了,现在不是WP就是z...@332347365,我当时接入时错误码没有-10...楼主,ChkValue值应为-103是什么意思呢?...大哥 你最近能看到我发的信息,请跟我联系,我有个制...
一段显示下载进度条的下载文件代码
编辑:dnawo 日期:2009-05-26
VB.NET
C#
复制内容到剪贴板
程序代码

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
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();
}
{
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();
}
评论: 0 | 引用: 0 | 查看次数: 3625
发表评论
请登录后再发表评论!