Parse Google GeoCode xml in VB.net - vb.net

Ok so I got my little chunck of code that goes out and brings back xml from google for my location after i send it the lat and long. What I now need to be able to do is just get one line out of it.
From the second result set I need to get formatted_address.
Never done any xml parsing in vb.net so I am way lost.
Dim webClient As New System.Net.WebClient
Dim result As String = webClient.DownloadString("http://maps.googleapis.com/maps/api/geocode/xml?latlng=44.46944050638752,-88.08779155546756&sensor=false")
Return result
After that I am lost!

In case anyone needs to know. I figured it out. Here is what i did:
Dim myAddress As String = "Nothing"
Dim webClient As New System.Net.WebClient
Dim result As String = webClient.DownloadString("http://maps.googleapis.com/maps/api/geocode/xml?latlng=lat,long&sensor=false")
Dim xmlDoc As New XmlDocument()
xmlDoc.LoadXml(result)
Dim m_nodelist As XmlNodeList
m_nodelist = xmlDoc.SelectNodes("/GeocodeResponse/result/formatted_address")
myAddress = m_nodelist(1).InnerText
result = myAddress

Related

VB.NET get a specific "href" by id

I need help to get start with my app.
I try to get HREF link from webpage without webbrowser.
I use HtmlAgilityPack but i cant get the spefic HREF:
<a id="ItemsList_file_0" title="HR9nqJCIqHex8niygKtwUHpdkjRGNaH22Oy54SPBmw.avi" href="http://dsa11.uverload.com/d/a012284e-1fd5-4317-82d3-9bf9e738f0a2/BIfmZ/0lOipBI/HR9nqJCIqHex8niygKtwUHpdkjRGNaH22Oy54SPBmw.avi" target="_blank">HR9nqJCIqHex8niygK..22Oy54SPBmw.avi</a><br />
i try this code .
Dim webreq As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://www.uverload.com/view/0lOipBI")
Dim webres As System.Net.HttpWebResponse = webreq.GetResponse
Dim sr As System.IO.StreamReader = New System.IO.StreamReader(webres.GetResponseStream)
Dim docStr As String = sr.ReadToEnd
Dim HAPdoc As New HtmlAgilityPack.HtmlDocument
HAPdoc.LoadHtml(docStr)
Dim HAPnode As HtmlAgilityPack.HtmlNode
HAPnode = HAPdoc.GetElementbyId("ItemsList_file_0")
MsgBox(HAPnode.InnerText)
End Sub
give me nothing

automatically download a report

This is the code that i have made but now working to save the report to the directory:
As you see i follow pretty much a lot of microsoft tutorials of how use this class of reporting service, but still dont get how get it working
'objetos de reporting
Dim rs As New reportingservice.ReportingService2010
Dim rsExec As New ReportExecution.ReportExecutionService
rs.Credentials = System.Net.CredentialCache.DefaultCredentials
'datos generales
Dim historyID As String = Nothing
Dim deviceInfo As String = Nothing
Dim format As String = "PDF"
Dim results As Byte()
Dim encoding As String = String.Empty
Dim mimeType As String = String.Empty
Dim extension As String = String.Empty
Dim warnings As ReportExecution.Warning() = Nothing
Dim streamIDs As String() = Nothing
Dim filename As String = "C:/Users/gdedieu/Desktop/reporte.pdf" ' Change to where you want to save
Dim _reportName As String = "per_anexo_1"
Dim _historyID As String = Nothing
Dim _forRendering As Boolean = False
Dim _values As ReportExecution.ParameterValue() = Nothing
Dim _credentials As reportingservice.DataSourceCredentials() = Nothing
Dim ei As ReportExecution.ExecutionInfo = rsExec.LoadReport(_reportName, historyID)
'definimos el parĂ¡metro
_values(0).Name = "an1_id"
_values(0).Value = 1
rsExec.SetExecutionParameters(_values, "en-us")
results = rsExec.Render(format, deviceInfo, extension, mimeType, encoding, warnings, streamIDs)
Dim stream As New System.IO.FileStream(filename, IO.FileMode.OpenOrCreate)
stream.Write(results, 0, results.Length)
stream.Close()
Try setting up a subscription via the Report Manager and specifying the Report Delivery Options value for 'Delivered By:' as 'Report Server File Share'.
This lets you specify a path for a report file to be written to - you will need to ensure that the Reporting Services server has write access to the destination.

How do I read text directly from a URL using VB.net?

I'm making a Windows Phone 8 app. I have the latitude and longitude of the target location. I need to get the Two Letter ISO country code of target location.
I'm using the following code to make it happen.
'Dim address As String = puri
'Dim client As WebClient = New WebClient()
'Dim reader As StreamReader = New StreamReader(address)
'code = reader.ReadToEnd
Dim inStream As StreamReader
Dim wr As WebRequest
Dim webresponse As WebResponse
wr = WebRequest.Create(puri)
webresponse = wr.GetResponse()
inStream = New StreamReader(webresponse.GetResponseStream())
code = inStream.ReadToEnd()
where puri(in the commented code) is the address of the webservice in string format.
When trying the commented code, the error I'm getting is that string cannot be converted to system.uri format. (address)
When trying the uncommented code, I get an error which says, getresponse is not a member of class system.net.webrequest()
I guess with the updates to .NET the code changed, but I couldn't find anything current on the topic.
URI = http://api.geonames.org/countryCode?lat=17.60890&lng=76.98966&username=demo
I think you should use WebClient Class instead of a WebRequest. It is simpler and faster. Here is a simple example:
Dim WebCL As New WebClient
Dim DownLoadedText As String = String.Empty
Try
DownLoadedText = WebCL.DownloadString("Your Url")
' Do something
Catch ex As Exception
Throw New Exception("Oops!! ERROR has occured, something is wrong with your address")
End Try

How to read returned stream data

I am currently reading a stream like this:
wc = New System.Net.WebClient()
strm = wc.OpenRead(url)
Data.ReadXml(strm, XmlReadMode.InferSchema)
strm.Close()
Besides the Dataset reading the stream I would also like to be able to output the text to the log file. Or for testing to a debug.print statement.
How can I do that? I have tried adding a new stream reader after the wc.openread but then there is no data for the dataset to read.
Any help would be appreciated..
Rick
after the
Data.ReadXml(strm, XmlReadMode.InferSchema)
call the Data.GetXml
Dim xmlString As String = Data.GetXml
Sample below,
Dim Data As New DataSet
Using wc = New System.Net.WebClient()
Using strm = wc.OpenRead("http://news.yahoo.com/rss/entertainment")
Data.ReadXml(strm, XmlReadMode.InferSchema)
Dim xmlString As String = Data.GetXml
Debug.WriteLine(xmlString)
End Using
End Using

Issue with StreamReader

I am writing code where I am trying to grab the HTML from a DNS report online (http://viewdns.info/dnsreport/?domain=google.com), but I am having some issues. The one line of the HTML file (Line 231) that I actually need is cutting itself off after around 680 characters. All of the lines after the important one are reading correctly, however. The code for grabbing the HTML is shown below, and I have tried it in two separate ways.
This is the first way I tried:
Public Function getWebResourceData(ByVal strURL As String) As String
Dim webClient As New System.Net.WebClient
Dim result As String = webClient.DownloadString("http://viewdns.info/dnsreport/?" & TextBox1.Text)
return result
End Function
And this is the second:
Public Function getWebResourceData(ByVal strURL As String) As String
Dim rt As String = ""
Dim wRequest As WebRequest
Dim wResponse As WebResponse
Dim SR As StreamReader
wRequest = WebRequest.Create(strURL)
wResponse = wRequest.GetResponse
SR = New StreamReader(wResponse.GetResponseStream)
rt = SR.ReadToEnd
SR.Close()
return rt
End Function
Im really not sure what else could be wrong at this point. I have also tried saving the result to a text file to see if that was the issue, but that was incorrect as well. I have looked into the hex codes for the area where the string is stopping, but there isn't anything out of the ordinary. The split occurs between the back to back alligator brackets (shown as parentheses) here: (/tr)(tr)
But there are numerous sets of these tags throughout the HTML that there are no issues with.
Both of your functions don't return what they have read. I have tested the second one and it works correctly.
Sub Main
Dim ret = getWebResourceData("http://viewdns.info/dnsreport/?domain=google.com")
Console.WriteLine(ret.Length)
' Output = 21605
End Sub
Public Function getWebResourceData(ByVal strURL As String) As String
Dim rt As String = ""
Dim wRequest As WebRequest
Dim wResponse As WebResponse
Dim SR As StreamReader
wRequest = WebRequest.Create(strURL)
wResponse = wRequest.GetResponse
SR = New StreamReader(wResponse.GetResponseStream)
rt = SR.ReadToEnd
SR.Close()
return rt
End Function