URI Formats are not supported

L

Lou Civitella

Using the following code I am trying to save changes to a xml from a VB.Net
app.
' Save the changes to the config file.
Dim xmlDoc As New XmlDocument
Dim strAppWorkingDir As String =
Path.GetDirectoryName([Assembly].GetExecutingAssembly.GetName.CodeBase) &
"\Config.xml"

xmlDoc.Load(strAppWorkingDir)
xmlDoc.GetElementsByTagName("Server").ItemOf(0).InnerXml =
txtServer.Text
xmlDoc.GetElementsByTagName("Database").ItemOf(0).InnerXml =
txtDatabase.Text
xmlDoc.GetElementsByTagName("UserName").ItemOf(0).InnerXml =
txtUserName.Text
xmlDoc.GetElementsByTagName("Password").ItemOf(0).InnerXml =
txtPassword.Text
xmlDoc.GetElementsByTagName("TimeOut").ItemOf(0).InnerXml =
txtTimeOut.Text
xmlDoc.GetElementsByTagName("Timer").ItemOf(0).InnerXml =
txtTimer.Text

Try
xmlDoc.Save(strAppWorkingDir)
Catch ex As Exception
MessageBox.Show(ex.Message)
Exit Function
End Try

MessageBox.Show("Settings Saved")

When the code hits the Save line I get this error message: URI formats are
not supported

Here is what the config file looks like:
<?xml version="1.0" encoding="utf-8" ?>

<Configuration>

<UserName>sa</UserName>

<Password>1234</Password>

<Database>Application</Database>

<Server>SQL</Server>

<TimeOut>30</TimeOut>

<Timer>5</Timer>

</Configuration>

What does this mean and how can I fix this problem?

Thanks,
Lou
 
H

Herfried K. Wagner [MVP]

Lou Civitella said:
' Save the changes to the config file.
Dim xmlDoc As New XmlDocument
Dim strAppWorkingDir As String =
Path.GetDirectoryName([Assembly].GetExecutingAssembly.GetName.CodeBase) &
"\Config.xml"

xmlDoc.Load(strAppWorkingDir)
xmlDoc.GetElementsByTagName("Server").ItemOf(0).InnerXml =
txtServer.Text
xmlDoc.GetElementsByTagName("Database").ItemOf(0).InnerXml =
txtDatabase.Text
xmlDoc.GetElementsByTagName("UserName").ItemOf(0).InnerXml =
txtUserName.Text
xmlDoc.GetElementsByTagName("Password").ItemOf(0).InnerXml =
txtPassword.Text
xmlDoc.GetElementsByTagName("TimeOut").ItemOf(0).InnerXml =
txtTimeOut.Text
xmlDoc.GetElementsByTagName("Timer").ItemOf(0).InnerXml =
txtTimer.Text

Try
xmlDoc.Save(strAppWorkingDir)
Catch ex As Exception
MessageBox.Show(ex.Message)
Exit Function
End Try

MessageBox.Show("Settings Saved")

When the code hits the Save line I get this error message: URI formats are
not supported

Can you post the value of 'strAppWorkingDir'?
 
L

Lou Civitella

Here is the path it is returning.
file:\C:\Documents and Settings\Administrator\My Documents\Visual Studio
Projects\FTP\FTP\bin\Config.xml

Thanks Again,
Lou

Herfried K. Wagner said:
Lou Civitella said:
' Save the changes to the config file.
Dim xmlDoc As New XmlDocument
Dim strAppWorkingDir As String =
Path.GetDirectoryName([Assembly].GetExecutingAssembly.GetName.CodeBase) &
"\Config.xml"

xmlDoc.Load(strAppWorkingDir)
xmlDoc.GetElementsByTagName("Server").ItemOf(0).InnerXml =
txtServer.Text
xmlDoc.GetElementsByTagName("Database").ItemOf(0).InnerXml =
txtDatabase.Text
xmlDoc.GetElementsByTagName("UserName").ItemOf(0).InnerXml =
txtUserName.Text
xmlDoc.GetElementsByTagName("Password").ItemOf(0).InnerXml =
txtPassword.Text
xmlDoc.GetElementsByTagName("TimeOut").ItemOf(0).InnerXml =
txtTimeOut.Text
xmlDoc.GetElementsByTagName("Timer").ItemOf(0).InnerXml =
txtTimer.Text

Try
xmlDoc.Save(strAppWorkingDir)
Catch ex As Exception
MessageBox.Show(ex.Message)
Exit Function
End Try

MessageBox.Show("Settings Saved")

When the code hits the Save line I get this error message: URI formats are
not supported

Can you post the value of 'strAppWorkingDir'?
 
H

Herfried K. Wagner [MVP]

Lou Civitella said:
Here is the path it is returning.
file:\C:\Documents and Settings\Administrator\My Documents\Visual Studio
Projects\FTP\FTP\bin\Config.xml

Either remove the "file:\" prefix or use this code:

\\\
Imports System.IO
Imports System.Reflection
..
..
..
Private Function ApplicationPath() As String
Return _
Path.GetDirectoryName([Assembly].GetExecutingAssembly().Location)
End Function
///
 
L

Lou Civitella

Thanks a lot Herfried I added this code that you gave me and it worked
great.
Path.GetDirectoryName([Assembly].GetExecutingAssembly().Location)

Thanks Again,
Lou

Herfried K. Wagner said:
Lou Civitella said:
Here is the path it is returning.
file:\C:\Documents and Settings\Administrator\My Documents\Visual Studio
Projects\FTP\FTP\bin\Config.xml

Either remove the "file:\" prefix or use this code:

\\\
Imports System.IO
Imports System.Reflection
.
.
.
Private Function ApplicationPath() As String
Return _
Path.GetDirectoryName([Assembly].GetExecutingAssembly().Location)
End Function
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top