none
WinCE.net下載一個執行檔 RRS feed

  • 問題

  • 我要做一個可以連線到網路 並且可以去下載他的執行檔

    在vb 2005 可以使用  My.Computer.Network.DownloadFile

    但是在 vb 2003 卻沒有my的功能,不知道 是否有哪個方式可以代替DownloadFile

    謝謝!!
    2007年9月7日 上午 08:21

解答

  • Imports System.Net
    Imports System.IO 

    ....................................................

     

    Public Sub DownloadFile(ByVal localFile As String, ByVal downloadUrl As String)
            Dim req As HttpWebRequest = CType(WebRequest.Create(downloadUrl), HttpWebRequest)

            req.Method = "GET"

            Dim resp As HttpWebResponse = CType(req.GetResponse(), HttpWebResponse)

            ' Retrieve response stream and wrap in StreamReader
            Dim respStream As Stream = resp.GetResponseStream()
            Dim rdr As New StreamReader(respStream)

            ' Create the local file
            Dim wrtr As New StreamWriter(localFile)

            ' loop through response stream reading each line
            '  and writing to the local file
            Dim inLine As String = rdr.ReadLine()
            While Not (inLine Is Nothing)
                wrtr.WriteLine(inLine)
                inLine = rdr.ReadLine()
            End While

            rdr.Close()
            wrtr.Close()
        End Sub 'DownloadFile

     

     

     

    Ref :http://msdn2.microsoft.com/en-us/library/aa446517.aspx

    2007年9月7日 上午 10:50

所有回覆

  • 你可以用HttpRequest去下載檔案。

     

    2007年9月7日 上午 08:29
  • 喔 這麼快就有回答了 那我趕快去試看看

     

    成功之後在把code貼上來

     

    謝謝!!

     

    2007年9月7日 上午 08:33
  • Imports System.Net
    Imports System.IO 

    ....................................................

     

    Public Sub DownloadFile(ByVal localFile As String, ByVal downloadUrl As String)
            Dim req As HttpWebRequest = CType(WebRequest.Create(downloadUrl), HttpWebRequest)

            req.Method = "GET"

            Dim resp As HttpWebResponse = CType(req.GetResponse(), HttpWebResponse)

            ' Retrieve response stream and wrap in StreamReader
            Dim respStream As Stream = resp.GetResponseStream()
            Dim rdr As New StreamReader(respStream)

            ' Create the local file
            Dim wrtr As New StreamWriter(localFile)

            ' loop through response stream reading each line
            '  and writing to the local file
            Dim inLine As String = rdr.ReadLine()
            While Not (inLine Is Nothing)
                wrtr.WriteLine(inLine)
                inLine = rdr.ReadLine()
            End While

            rdr.Close()
            wrtr.Close()
        End Sub 'DownloadFile

     

     

     

    Ref :http://msdn2.microsoft.com/en-us/library/aa446517.aspx

    2007年9月7日 上午 10:50