ok, I am working on a program for work and I am stuck on trying to make a new XML file from VB.NET 2010. I have the old code which was done in C# and it works but even using a C# to VB converter didn't help. I will paste in both the C# and what I have in VB and maybe someone can help me out.
private void webBrowser1_Navigating(object sender,
WebBrowserNavigatingEventArgs e)
{
int index;
string loc_url = "";
string sid = "";
System.Windows.Forms.HtmlDocument document =
this.webBrowser1.Document;
// e.Cancel = true;
loc_url = e.Url.ToString();
index = loc_url.IndexOf("&sid=", 0, loc_url.Length);
if ((index > 15))
{
index = index + 5; // offset the &sid=
sid = loc_url.Substring(index, loc_url.Length - index);
if (sid.Contains("session"))
return;
XmlDocument doc = new XmlDocument();
XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
doc.AppendChild(docNode);
XmlNode chunkDataNode = doc.CreateElement("ChunkData");
doc.AppendChild(chunkDataNode);
XmlNode fieldNode = doc.CreateElement("fields");
chunkDataNode.AppendChild(fieldNode);
XmlNode field6Node = doc.CreateElement("field6");
field6Node.AppendChild(doc.CreateTextNode(sid));
fieldNode.AppendChild(field6Node);
string path = @"C:\Dictaphone";
try
{
// Determine whether the directory exists.
if (Directory.Exists(path))
{
doc.Save(path + @"\Study.xml");
}
else
{
// Try to create the directory.
DirectoryInfo di = Directory.CreateDirectory(path);
if (Directory.Exists(path))
{
doc.Save(path + @"\Study.xml");
}
}
}
catch (Exception exc)
{
Console.WriteLine("The process failed: {0}", exc.ToString());
}
finally { }
}
}
is the C# code and it works.
Here is what I have in VB that doesn't work.
Private Sub WebBrowser1_Navigating(ByVal sender As Object, ByVal e As WebBrowserNavigatingEventArgs)
Dim index As Integer
Dim loc_url As String = ""
Dim sid As String = ""
Dim document As HtmlDocument = Me.WebBrowser1.Document
' e.Cancel = true;
loc_url = e.Url.ToString()
index = loc_url.IndexOf("&sid=", 0, loc_url.Length)
If (index > 15) Then
index = index + 5 ' offset the &sid=
sid = loc_url.Substring(index, loc_url.Length - index)
If sid.Contains("session") Then
Return
End If
End If
Dim doc As New XmlDocument()
Dim docNode As XmlNode = doc.CreateXmlDeclaration("1.0", "UTF-8", Nothing)
doc.AppendChild(docNode)
Dim chunkDataNode As XmlNode = doc.CreateElement("ChunkData")
doc.AppendChild(chunkDataNode)
Dim fieldNode As XmlNode = doc.CreateElement("fields")
chunkDataNode.AppendChild(fieldNode)
Dim field6Node As XmlNode = doc.CreateElement("field6")
field6Node.AppendChild(doc.CreateTextNode(sid))
fieldNode.AppendChild(field6Node)
Dim path As String = "C:\Dictaphone"
Try
' Determine whether the directory exists.
If Directory.Exists(path) Then
doc.Save("C:Dictaphone\Study.xml")
Else
' Try to create the directory.
Dim di As DirectoryInfo = Directory.CreateDirectory(path)
If Directory.Exists(path) Then
doc.Save("C:Dictaphone\Study.xml")
End If
End If
Catch exc As Exception
Console.WriteLine("The process failed: {0}", exc.ToString())
Finally
End Try
End Sub
And last but not least, this is what the XML file should look like.
<?xml version="1.0" encoding="UTF-8" ?>
- <ChunkData>
- <fields>
<field6>188163</field6>
</fields>
</ChunkData>
It is supposed to not only create the file but launch a program called PowerScribe and find the case in the Field 6 section.
Any help would be greatly appreciated.