Click here to Skip to main content
15,906,467 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi


I want to read csv file from the following URL

http://www.votrecourse.com/medias/xml/?C=M;O=D/"

file name = timetrial.csv

i tried the code.. its showing all files inside the web..
But iwant to read data only from timetrial.csv

What I have tried:

Dim client As New WebClient()
        Dim data As String = client.DownloadString("http://www.votrecourse.com/medias/xml/?C=M;O=D/timetrial.csv")

        Dim table As New DataTable()
        Using parser As New TextFieldParser(New StringReader(data))
            parser.TextFieldType = FieldType.Delimited
            parser.SetDelimiters(",")
            Dim headers() As String = parser.ReadFields()
            For Each header As String In headers
                table.Columns.Add(header)
            Next
            While Not parser.EndOfData
                Dim fields() As String = parser.ReadFields()
                table.Rows.Add(fields)
            End While
        End Using

        DataGridView1.DataSource = table
Posted
Updated 25-Jan-23 21:28pm

I used your URL in a web browser and saw the list of files in that directory. I found the file and right-clicked on it and selected "copy link address". I paste the link in a web browser and the file opened up.

Here is that link:
http://www.votrecourse.com/medias/xml/Timetrial.csv


As for downloading the file, there are a number of different techniques. The simplest is:
VB
Dim Text = Await New HttpClient().GetStringAsync("http://www.votrecourse.com/medias/xml/Timetrial.csv")
File.WriteAllText("Timetrial.csv", Text)
 
Share this answer
 
Have a look at
WebClient.DownloadFile Method (System.Net) | Microsoft Learn[^]
You will see that here are two overloads of DownloadFile.
You must use the
DownloadFile(String, String)
overload, which accepts a filename as second argument.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900