50分求好心人翻译,关于httwebprequest下载的,把c#翻译成vb.net的,10行左右,我翻译了个头,后面弄不明白了
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();
}
请哪位好心人帮翻译成vb.net的,我翻译了一点。。。。
Public Sub DownFile(ByVal URL As String, ByVal Filename As String)
Dim Myrq As HttpWebRequest = WebRequest.Create(URL)
Dim Myrp As HttpWebResponse = Myrq.GetResponse()
Dim j As Long = myrp.ContentLength() '获取长度
Dim st As System.IO.Stream = Myrp.GetResponseStream()
'.....请求好心人闪亮登场..
'.....请求好心人闪亮登场.
End Sub
[解决办法]
Public Shared Sub DownFile(URL As String, Filename As String, Prog As ProgressBar)
Dim Myrq As System.Net.HttpWebRequest = DirectCast(System.Net.HttpWebRequest.Create(URL), System.Net.HttpWebRequest)
Dim myrp As System.Net.HttpWebResponse = DirectCast(Myrq.GetResponse(), System.Net.HttpWebResponse)
Dim totalBytes As Long = myrp.ContentLength
Prog.Maximum = CInt(totalBytes)
Dim st As System.IO.Stream = myrp.GetResponseStream()
Dim so As System.IO.Stream = New System.IO.FileStream(Filename, System.IO.FileMode.Create)
Dim totalDownloadedByte As Long = 0
Dim by As Byte() = New Byte(1023) {}
Dim osize As Integer = st.Read(by, 0, CInt(by.Length))
While osize > 0
totalDownloadedByte = osize + totalDownloadedByte
Application.DoEvents()
so.Write(by, 0, osize)
Prog.Value = CInt(totalDownloadedByte)
osize = st.Read(by, 0, CInt(by.Length))
End While
so.Close()
st.Close()
End Sub
[解决办法]
http://www.developerfusion.com/tools/convert/csharp-to-vb/ C#转vb.net