[RESOLVED] [2008] understanding my.settings
I'm in the process of upgrading from vb6 to .net and still a little new to it. I've been reading up everywhere i can find on my.settings. Previously I had been using an .ini file. At run time I was able to open that file and modify it if necessary:
Code:
Dim theiniid As Double
ChDir App.Path
If Dir("myinifile.ini") <> "" Then
theiniid = Shell("Notepad myinifile.ini", vbMaximizedFocus)
End If
The first thing I've been trying to resolve is that the My.settings config file gets stored several levels deep into the users documents dir. Whats the VB code to access that path since its local per user per OS?
Secondly since the style type is changing from *.ini to *.xml ive been considering creating a form to show these items instead. XML isn't as clean to look at, a form with a listbox would be much easier on the eyes.
Some code i've found to generate this:
Code:
For Each item As System.Configuration.SettingsProperty In My.Settings.Properties
listbox1.items.additem(item.name)
Next
The problem with this batch of code is that item.value doesnt exist, is there a way to access that via this method?
Another thing I've noticed is that during the inital stage of the code I declare
Code:
mainform.hide
formnumber2.show
irrigardless the primary form pops up anyways. Anyone know how to stop that?
Thanks
Re: [2008] understanding my.settings
In solution explorer right click on My Project, click on the Settings tab. This is where you enter the information that you want to persist. Once you have done that when you enter My.Settings. intellisense will display all the settings that you have created.
For instance if you had created a setting Named AppPath and given a string type and the path intellisense would show AppPath
Once you have done that go the Application tab and check Save My.Settings on shut down.
Hope this helps:)
Re: [2008] understanding my.settings
I've already gotten that far. What i want to do now is take, for example, all of the strings that are being maintained there and populate them into a listbox or bring up the configuration file that keeps them for editing at the run time.
Re: [2008] understanding my.settings
Re: [2008] understanding my.settings
Re: [2008] understanding my.settings
Oh I see your problem now.
The file is in the project directory and is named app.config. Since I am not familiar with XML I am affraid this is as far as I can help you. I think that you will need to recurse through the nodes to get the info.
If you have a common name like appPath1, appPath2, appPath3, appPath4 and so on you could use a for loop using My.Settings.AppPath & i
Re: [2008] understanding my.settings
Or use the index
Code:
My.Settings.Item(i)
Re: [2008] understanding my.settings
Code:
For Each item As System.Configuration.SettingsProperty In My.Settings.Properties
If My.Settings.Item(item.Name) IsNot Nothing Then
ListBox1.Items.Add(My.Settings.Item(item.Name))
End If
Next item
yep that did it, thanks
Re: [RESOLVED] [2008] understanding my.settings
Good for you. If that solves your problem you may want to mark this thread as resolved.