We help IT Professionals succeed at work.

Where are VB.NET settings held?

Sancler
Sancler asked
on
I have a Visual Basic 2010 Express project that I'm developing.  It includes an option to change the font in some display grids.  Here's the code.

Private Sub btnFont_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFont.Click
        FontPicker.Font = My.Settings.GridFont
        Dim result As DialogResult = FontPicker.ShowDialog
        If result = DialogResult.OK Then
            Dim newfont As Font = FontPicker.Font
            My.Settings.GridFont = newfont
        End If
        My.Settings.Save()
        lblFont.Font = My.Settings.GridFont
    End Sub

Open in new window


It works, there's no problem from that point of view.  Not only is the change in font reflected while the project is running but it is also retained from one run to the next, including over a full system shutdown.

But what I cannot work out is where that selection is stored.  If I look at the settings tab in Project Properties it never changes: it is always set at Microsoft Sans Serif, 8.25pt, even when the font actually being used is, for instance, Comic Sans MS, Bold Oblique, 10pt.  I've inspected all the settings and config files I can find in the project directory and all sub-directories, but can find nothing apart from Microsoft Sans Serif, 8.25pt.  But the changed value must be being stored somewhere or it wouldn't work.

Where is it?

Roger
Comment
Watch Question

Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:
it should be in a file somewhere under C:\Documents and Settings\UserName\Local Settings\Application Data

Author

Commented:
Sorry, should have said, this is on Windows 7.  So the equivalent, I think, would be C:\Users\Roger\AppData\Local\CSAccts or C:\Program Files (x86)\CSAccts (which is where the database resides - for the moment) or C:\Users\Roger\AppData\Local\VirtualStore\Program Files (x86)\CSAccts.  Nothing in any of those.

But the application hasn't been published yet.  I'm running it from the VBExpress IDE.  I've run it in both Debug and Release modes.  So I've been looking in the project directory bin/Debug and bin/Release folders and obj/x86/Debug and obj/x86/Release folders.  Plenty of files to inspect in there but all that I recognise as possible candidates (.config and .settings) show the Microsoft Sans Serif, 8.25pt even when the font that will in fact be used - that is, what the progam reads from "My.Settings.GridFont" in line 2 of the code above - has been changed to something different.

Roger

Author

Commented:
Oops.  Change "/" to "\" in those paths above.
Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:
when I run my demo, I see this folder C:\Users\Eric Moreau\AppData\Local\Demo which contains some subfolder to ultimately find user.config
Most Valuable Expert 2012
Top Expert 2008

Commented:
I don't see where you are calling My.Settings.Save()...

Author

Commented:
emoreau

No, there's no equivalent to that.  There is a folder with the name of the project.  But it has no sub-folders and no user.config file in it.

TheLearnedOne

How about line 8?

I'm going to do a system wide search for all user.config files and see if I can find it that way.  It'll take ages, but I'll report back.

Roger

Author

Commented:
Found it.  Here's the path

C:\Users\Roger\AppData\Local\Hewlett-Packard_Company\csaccts.vshost.exe_Url_mmmu432yfqm1qjpaodxqavxl3icrudij\1.0.0.0

I can think of no sensible reason why it should be in a "Hewlett-Packard_Company" folder.  I'm using an HP desktop machine, but ...

Any ideas?

Roger
Senior .Net Consultant
Top Expert 2016
Commented:
What is the the namespace of your application?

Author

Commented:
csaccts

But I've now discovered the root cause.  I looked at the Assembly Information in the Application tab in the Project Properties and discovered that Company: was set to Hewlett-Packard_Company.  How that happened, Heaven only knows.  But I got rid of that, re-ran, and now I am getting a user.config file in a sub-folder of C:\Users\Roger\AppData\Local\CSAccts with the changed font name, etc. in it.

So, it's sorted (not that it wasn't working, in the first place, but not understanding what was going on was bugging me).

Points to emoreau for nudging me towards looking for all user.config files.

Thanks