By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,326 Members | 838 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,326 IT Pros & Developers. It's quick & easy.

Using My.settings in VB2005

P: n/a
Hello,

I have a few questions about the My.Settings user configuration.

Is it posible to change the filepath of the my.settings userconfig file ?

Is it posible to have different files so i can group my setting by type ?

In my Application i need to store a lot of different parameters
and i want a different file for each group.

Thanks in advanced

Hans
Mar 24 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Hi,

You can store the information in an xml file. You will not have use
of the my namespace to load the values.

Ken
----------------
"Hans" <Ha**@discussions.microsoft.com> wrote in message
news:EB**********************************@microsof t.com...
Hello,

I have a few questions about the My.Settings user configuration.

Is it posible to change the filepath of the my.settings userconfig file ?

Is it posible to have different files so i can group my setting by type ?

In my Application i need to store a lot of different parameters
and i want a different file for each group.

Thanks in advanced

Hans

Mar 27 '06 #2

P: n/a
Hello Ken,

Thanks for your answer,

What is the best way to read and write to the XML file, must i use a
XMLDocument or a xmldatadocument ?

"Ken Tucker [MVP]" wrote:
Hi,

You can store the information in an xml file. You will not have use
of the my namespace to load the values.

Ken
----------------
"Hans" <Ha**@discussions.microsoft.com> wrote in message
news:EB**********************************@microsof t.com...
Hello,

I have a few questions about the My.Settings user configuration.

Is it posible to change the filepath of the my.settings userconfig file ?

Is it posible to have different files so i can group my setting by type ?

In my Application i need to store a lot of different parameters
and i want a different file for each group.

Thanks in advanced

Hans


Mar 27 '06 #3

P: n/a
Hi Hans,

for writing XML files I use

Private Function CreateXMLFile(ByVal FileName As String) As String

Try

' Create the name for the new XML file depending on the given name

Dim NewObjectFile As String = _NodesDir + "\" + FileName + XMLPostfix

Dim myFileInfo As FileInfo = New FileInfo(NewObjectFile)

' Check if a file with this name already exists

If myFileInfo.Exists = True Then

Return "error"

End If

' We passed all the syntax checks -- write the config to the new XML file

_XML = New XmlTextWriter(NewObjectFile, System.Text.Encoding.Default)

With _XML

' Activate Indented

..Formatting = Formatting.Indented

' Write start declarations

..WriteStartDocument()

' Start with root element

..WriteStartElement("config")

' Write the current date as comment

..WriteComment(Date.Now.ToString)

End With

Catch ex As Exception

Return ex.ToString

End Try

' Success

Return "0"

End Function


Private Function FinishXMLFile() As String

Try

With _XML

..WriteEndElement() ' Ends "config" node

..Flush()

..Close()

End With

Catch ex As Exception

End Try

' Success

Return "0"

End Function

Hope this helps,

Josef

"Hans" <Ha**@discussions.microsoft.com> schrieb im Newsbeitrag
news:23**********************************@microsof t.com...
Hello Ken,

Thanks for your answer,

What is the best way to read and write to the XML file, must i use a
XMLDocument or a xmldatadocument ?

"Ken Tucker [MVP]" wrote:
Hi,

You can store the information in an xml file. You will not have
use
of the my namespace to load the values.

Ken
----------------
"Hans" <Ha**@discussions.microsoft.com> wrote in message
news:EB**********************************@microsof t.com...
> Hello,
>
> I have a few questions about the My.Settings user configuration.
>
> Is it posible to change the filepath of the my.settings userconfig file
> ?
>
> Is it posible to have different files so i can group my setting by type
> ?
>
> In my Application i need to store a lot of different parameters
> and i want a different file for each group.
>
> Thanks in advanced
>
> Hans


Mar 27 '06 #4

P: n/a
Hi Josef,

Thanks,

Can you give me an example of how to read and write to an xml file >

Hans
"Josef Brunner" wrote:
Hi Hans,

for writing XML files I use

Private Function CreateXMLFile(ByVal FileName As String) As String

Try

' Create the name for the new XML file depending on the given name

Dim NewObjectFile As String = _NodesDir + "\" + FileName + XMLPostfix

Dim myFileInfo As FileInfo = New FileInfo(NewObjectFile)

' Check if a file with this name already exists

If myFileInfo.Exists = True Then

Return "error"

End If

' We passed all the syntax checks -- write the config to the new XML file

_XML = New XmlTextWriter(NewObjectFile, System.Text.Encoding.Default)

With _XML

' Activate Indented

..Formatting = Formatting.Indented

' Write start declarations

..WriteStartDocument()

' Start with root element

..WriteStartElement("config")

' Write the current date as comment

..WriteComment(Date.Now.ToString)

End With

Catch ex As Exception

Return ex.ToString

End Try

' Success

Return "0"

End Function


Private Function FinishXMLFile() As String

Try

With _XML

..WriteEndElement() ' Ends "config" node

..Flush()

..Close()

End With

Catch ex As Exception

End Try

' Success

Return "0"

End Function

Hope this helps,

Josef

"Hans" <Ha**@discussions.microsoft.com> schrieb im Newsbeitrag
news:23**********************************@microsof t.com...
Hello Ken,

Thanks for your answer,

What is the best way to read and write to the XML file, must i use a
XMLDocument or a xmldatadocument ?

"Ken Tucker [MVP]" wrote:
Hi,

You can store the information in an xml file. You will not have
use
of the my namespace to load the values.

Ken
----------------
"Hans" <Ha**@discussions.microsoft.com> wrote in message
news:EB**********************************@microsof t.com...
> Hello,
>
> I have a few questions about the My.Settings user configuration.
>
> Is it posible to change the filepath of the my.settings userconfig file
> ?
>
> Is it posible to have different files so i can group my setting by type
> ?
>
> In my Application i need to store a lot of different parameters
> and i want a different file for each group.
>
> Thanks in advanced
>
> Hans


Mar 27 '06 #5

P: n/a
Hi Hans,

"Hans" <Ha**@discussions.microsoft.com> schrieb im Newsbeitrag
news:37**********************************@microsof t.com...
Can you give me an example of how to read and write to an xml file >


use the functions provided in my last posting to create the object and start
writing an xml file and the other one to close everything. Then, for
writing, you can use something like this

With _XML

' Write data

..WriteStartElement("PortRange")

..WriteAttributeString("Name", RangeName)

..WriteAttributeString("Protocol", Protocol)

..WriteAttributeString("RangeStart", RangeStart.ToString)

..WriteAttributeString("RangeStop", RangeStop.ToString)

..WriteEndElement()

End With

and for reading:

If myFile.Exists = True Then

Dim xr As New XmlTextReader(myFile.FullName)

Do While xr.Read()

If xr.NodeType = XmlNodeType.Element Then

If String.Equals(xr.Name, "PortRange") Then

' This XML file holds a single generic port config

myPort.Type = "PortRange"

myPort.Name = xr.GetAttribute("Name")

myPort.Protocol = xr.GetAttribute("Protocol")

myPort.RangeStart = System.Convert.ToInt32(xr.GetAttribute("RangeStart "))

myPort.RangeStop = System.Convert.ToInt32(xr.GetAttribute("RangeStop" ))

' Finish reading this file

Exit Do

End If

End If

Loop ' Loop through the XML file

xr.Close() ' Close the file we just read!

End If

Hope it helps

Josef
Mar 27 '06 #6

P: n/a
Hi Josef,

How do i make a xsd file and how do i validate the content of the xml file

Hans

"Josef Brunner" wrote:
Hi Hans,

"Hans" <Ha**@discussions.microsoft.com> schrieb im Newsbeitrag
news:37**********************************@microsof t.com...
Can you give me an example of how to read and write to an xml file >


use the functions provided in my last posting to create the object and start
writing an xml file and the other one to close everything. Then, for
writing, you can use something like this

With _XML

' Write data

..WriteStartElement("PortRange")

..WriteAttributeString("Name", RangeName)

..WriteAttributeString("Protocol", Protocol)

..WriteAttributeString("RangeStart", RangeStart.ToString)

..WriteAttributeString("RangeStop", RangeStop.ToString)

..WriteEndElement()

End With

and for reading:

If myFile.Exists = True Then

Dim xr As New XmlTextReader(myFile.FullName)

Do While xr.Read()

If xr.NodeType = XmlNodeType.Element Then

If String.Equals(xr.Name, "PortRange") Then

' This XML file holds a single generic port config

myPort.Type = "PortRange"

myPort.Name = xr.GetAttribute("Name")

myPort.Protocol = xr.GetAttribute("Protocol")

myPort.RangeStart = System.Convert.ToInt32(xr.GetAttribute("RangeStart "))

myPort.RangeStop = System.Convert.ToInt32(xr.GetAttribute("RangeStop" ))

' Finish reading this file

Exit Do

End If

End If

Loop ' Loop through the XML file

xr.Close() ' Close the file we just read!

End If

Hope it helps

Josef

Mar 27 '06 #7

P: n/a
Hans,

xml validation:
http://msdn.microsoft.com/library/de...hXmlReader.asp

(I've never used this class...)

I'm sorry, but I did not have the need to work with xsd files yet...
Bye,
Josef

"Hans" <Ha**@discussions.microsoft.com> schrieb im Newsbeitrag
news:19**********************************@microsof t.com...
Hi Josef,

How do i make a xsd file and how do i validate the content of the xml file

Hans

"Josef Brunner" wrote:
Hi Hans,

"Hans" <Ha**@discussions.microsoft.com> schrieb im Newsbeitrag
news:37**********************************@microsof t.com...
> Can you give me an example of how to read and write to an xml file >


use the functions provided in my last posting to create the object and
start
writing an xml file and the other one to close everything. Then, for
writing, you can use something like this

With _XML

' Write data

..WriteStartElement("PortRange")

..WriteAttributeString("Name", RangeName)

..WriteAttributeString("Protocol", Protocol)

..WriteAttributeString("RangeStart", RangeStart.ToString)

..WriteAttributeString("RangeStop", RangeStop.ToString)

..WriteEndElement()

End With

and for reading:

If myFile.Exists = True Then

Dim xr As New XmlTextReader(myFile.FullName)

Do While xr.Read()

If xr.NodeType = XmlNodeType.Element Then

If String.Equals(xr.Name, "PortRange") Then

' This XML file holds a single generic port config

myPort.Type = "PortRange"

myPort.Name = xr.GetAttribute("Name")

myPort.Protocol = xr.GetAttribute("Protocol")

myPort.RangeStart = System.Convert.ToInt32(xr.GetAttribute("RangeStart "))

myPort.RangeStop = System.Convert.ToInt32(xr.GetAttribute("RangeStop" ))

' Finish reading this file

Exit Do

End If

End If

Loop ' Loop through the XML file

xr.Close() ' Close the file we just read!

End If

Hope it helps

Josef

Mar 27 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.