Reputation: 2567
I need to know how can I read an INI file that is on the internet without download it into the computer, can save it into memory, I need to do this with Visual Basic 2010.
I need to read all content and get every value from every section but without download the file, I've tried with this class:
Question: Read and write in INI file
But only works with computer-stored-files, not with files on internet, I've been thinking in get all content of the INI file and save it into a string, but the class doesn't read it at all, can anyone help me? Thanks in advanced.
Upvotes: 0
Views: 683
Reputation: 1546
If you can, the easiest way is to download the file to a temp location. Use CreateTempFile to get a temp file name.
If you can't save the file at all, you can download it to memory with the following (untested):
Dim request As HttpWebRequest
Dim response As HttpWebResponse
request = Net.HttpWebRequest.Create(url) ' url of the file
request.Method = "GET"
response = request.GetResponse()
Using reader As StreamReader = New StreamReader(response.GetResponseStream(), Encoding.Default)
Dim fileStr As String = reader.ReadToEnd() ' fileStr contains the contents of the file
End Using
Upvotes: 1
Reputation:
The best thing you can do is reading the file as a webpage (basically, this is what it is) and then parsing all the information you get. I have used the code below many times and works pretty well:
Public Class Form1
Friend WithEvents webBrower0 As New WebBrowser
Friend WithEvents tabs As New TabControl
Friend WithEvents tabPage0 As New TabPage
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
startBrowser()
End Sub
Public Sub startBrowser()
Dim url As String = "http://..."
tabs.Controls.Add(tabPage0)
tabPage0.Controls.Add(webBrower0)
AddHandler webBrower0.Navigating, AddressOf WebBrowser_Navigating
AddHandler webBrower0.DocumentCompleted, AddressOf WebBrowser_DocumentCompleted
tabPage0.Refresh()
webBrower0.Navigate(url)
End Sub
Private Sub WebBrowser_Navigating(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs)
End Sub
Private Sub WebBrowser_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
Dim source_string As String = webBrower0.DocumentText 'content of the file
End Sub
End Class
After reading everything, the string source_string
will be populated with the file content. It follows the html format but you shouldn't find any problem to extract the information you want.
Upvotes: 1