• 0

open file from network/internet (Visual Basic)


Question

Hi all,

I was hoping you guys could help me out with this...

I am trying to open a file over the network or on a webpage... currently i can only open the file if it is stored locally (i.e. c:\filename.ext)

The code i used is this:

Open "C:\events.txt" For Input As #1
        Input #1, NumEvents
        For i = 0 To NumEvents - 1
            Input #1, Events(i)
            Input #1, EventInfo(i)
        Next i
    Close #1
    
    For i = 0 To NumEvents - 1
        LSTevents.AddItem Events(i)
    Next i

This will get the data in the txt file and load it into the list box, and then get the other data in the txt file and put it on the label caption.

If anyone knows how to do this but be able to open the file if the file is located on a website or on another computer on a network, please let me know.

I am using vb6.

Thanks

1 answer to this question

Recommended Posts

  • 0

here... found this at msdn and online... if anyone else has the same question as i did.. here ya go......

how to do it without using winsock or inet ocx etc..........

Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long

Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
    Dim lngRetVal As Long
    lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
    If lngRetVal = 0 Then DownloadFile = True
End Function

downloads file, then opens it locally

Private Sub Command1_Click()
DownloadFile "http://www.domain.com/file.EXT", "c:\file.EXT"

listbox1.Clear

    Open "C:\file.EXT" For Input As #1
        Input #1, NumItems
        For i = 0 To NumItems - 1
            Input #1, Item(i)
            Input #1, ItemInfo(i)
        Next i
    Close #1
    
    For i = 0 To NumItems - 1
        listbox1.AddItem Item(i)
    Next i
End Sub

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.