How can I use a Resource as a string parameter? - vb.net

I want to use an XML-File for my Dataset to save changes.
datatable.ReadXml("C:\test.xml")
works fine. But I want to use an Xml Resource file. So I tried
Dim xmlDoc as String
xmlDoc = MyApplication.My.Resources.xmlTestFile
datatable.ReadXml(xmlDoc)
gives me the error Illigal sign in path and debugging shows me that xmlDoc is empty.
Could anyone help me get this working?

ReadXml requires a filename not content
use
Dim ds As New DataSet()
Using stringReader As New StringReader(.......RESOURCE.HERE.......)
ds = New DataSet()
ds.ReadXml(stringReader)
End Using
Dim dt As DataTable = ds.Tables(0)

Related

HTTP Get in VB.Net how do I pass in the code from the body?

There are a lot of examples of how to add parameters into WebClient but how do you pass in the code you have in the body (see my response below with image of what it looks like in Postman)? Below is my code:
Using client As New WebClient()
client.Headers(HttpRequestHeader.Authorization) = AuthToken
client.QueryString.Add("parameter1", "Hello world") 'Pass in parameter, but not sure how to pass in code from Body
Dim json As String = client.DownloadString("https://www.zohoapis.com/crm/v2/Products")
Dim ds1 As DataTable = GetDataTableFromJsonString(json)
Dim BindingSource1 = New BindingSource
BindingSource1.DataSource = ds1
DataGridView1.DataSource = BindingSource1
End Using
Any help would be greatly appreciated.
Thanks,
Paul
I tried client.QueryString.Add() to see if I can just put that string in there but it didn't work.

how to create a lucene index only in one readable xml format

I am using below code for it but its give so many files and I want only one file in xml format so pls give me a proper way to create a lucene index in xml format.
Dim BibliDS As New DataSet
Dim DataDS As New DataSet
Dim dt As DataTable
Dim strTagSbFld As String
strTagSbFld = GetTagSbFldSQL()
conn.Open()
Dim strSQL As String = (strTagSbFld)
adap.SelectCommand = New SqlCommand(strSQL, conn)
adap.Fill(DataDS)
conn.Close()
DataDS.WriteXml("C:\Users\Shahrukh\Documents\Visual Studio 2012\Projects\Simple search1\Simple search1\New folder\Data.xml")
'MsgBox("XML Done")
Dim directory As Directory = FSDirectory.GetDirectory("C:\Users\Shahrukh\Documents\Visual Studio 2012\Projects\Simple search1\Simple search1\New folder ")
Dim analyzer As Lucene.Net.Analysis.Analyzer = New SimpleAnalyzer()
Dim indexWriter As New IndexWriter(directory, analyzer)
indexWriter.SetRAMBufferSizeMB(10.0)
indexWriter.SetUseCompoundFile(False)
indexWriter.SetMaxMergeDocs(10000)
indexWriter.SetMergeFactor(100)
dt = DataDS.Tables(0)
If dt IsNot Nothing Then
If dt.Rows.Count > 0 Then
For Each dr As DataRow In dt.Rows
'Create the Document object
Dim doc As New Document()
For Each dc As DataColumn In dt.Columns
'Populate the document with the column name and value from our query
doc.Add(New Field(dc.ColumnName, dr(dc.ColumnName).ToString(), Field.Store.YES, Field.Index.TOKENIZED))
Next
' Write the Document to the catalog
indexWriter.AddDocument(doc)
Next
End If
Else
MsgBox("No Data")
End If
'indexWriter.Optimize()
'Close the writer
indexWriter.Flush()
indexWriter.Close()
End Sub
pls give me a proper way to create a lucene index only in one file in xml format.
Short answer: You can't.
Why would you want to do this, anyway? Performance would be terrible.
To get an overview of the different files lucene creates, take a look at Index File Formats.

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

Output XmlDocument as XML

I have a function which reads a string to an XMLDocument.
I wish to then output the XML in that document to the screen.
Dim L As String = P.ToString()
Dim xmlDoc As XmlDocument = New XmlDocument()
xmlDoc.LoadXml(L)
Context.Response.Write(xmlDoc)
the above does not work, I have also tried using
Return(xmlDoc)
with no success. How should I perform this function? Should I not be using XMLDocument?
One of the possible ways is to use a StringWriter:
Using stringWriter = New StringWriter()
Using xmlTextWriter = XmlWriter.Create(stringWriter)
xmlDoc.WriteTo(xmlTextWriter)
xmlTextWriter.Flush()
result = stringWriter.GetStringBuilder().ToString()
End Using
End Using
On the example above, your XML will be stored into the result variable.
The C# equivalent code may be found on this thread.
StringWriter stringWriter = new StringWriter();
XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);
document.WriteTo(xmlTextWriter);
Console.WriteLine(stringWriter.ToString());
Console.Read();

Parse Google GeoCode xml in 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