Avatar of eeyo
eeyo
 asked on

VB.NET 2015+ Best place to save application scope data

In VB.NET, where is the best place to save application scope data?  I am looking to save one or more data files to be used to persist application-level settings and configurations between different users.

This doesn't seem to work as each user as Windows seems to call up their own virtual copy of the file.
      Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)

My.Settings only works for user-scope settings.  The application-scope settings get reset when the application is reloaded ... i.e. the data doesn't persist.
Visual Basic.NETWindows OS

Avatar of undefined
Last Comment
eeyo

8/22/2022 - Mon
Scott McDaniel (EE MVE )

There are Application level settings, but those are typically set at design or deployment, and a standard user would not be able to change/add to those because of UAC. .NET offers the ConfigurationManager, but you're liable to run into the same issue with UAC.

You can always use the registry to store those, but you may also run into UAC issues with that as well.

You can resort to the old INI file approach, or something similar. I use an XML file stored in the Roaming\<NameOfMyProgram>, which seems to work fine.
eeyo

ASKER
Would this be the appropriate path for the "Roaming" folder (+\ + NameOfMyProgram)?
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

Open in new window

gives me C:\Users\<user name>\AppData\Roaming but that folder and the files within it would be different if another user logged in.
ASKER CERTIFIED SOLUTION
Scott McDaniel (EE MVE )

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
eeyo

ASKER
I figured out what one of my problems was.  I was using ClickOnce which uses a strange virtualized folder.  I went through the ordeal of figuring out that I needed to download the Visual Studio Installer (doesn't come standard).  I will try to tinker with it more now ...
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
eeyo

ASKER
So, I just tried using Environment.SpecialFolder.CommonApplicationData (C:\ProgramData\ in Win 10).  Reading and writing files there are fine if you are an admin user, but if you log in as a standard user, you will get an access denied error.  Any other thoughts?

I even tried adding a custom "MyConfig.xml" file to the Project (selecting "Copy to Output Directory"), which means it installs in the startup directory.  Even the admin user that installed the application can't write to this custom file.

Any other thoughts?
Scott McDaniel (EE MVE )

Only other thing I could suggest would be either (a) a database or (b) a Public Document folder for your xml file.
eeyo

ASKER
Any thoughts about these possibilities:

1) Using the good old Windows Registry?  Is there a reason why it has fallen out of favor?  In this case, I might have to dump an XML file into one of the registry keys.  Is there a max string length for registry keys?
2) Creating a Resource file (Project menu -> Properties -> Resources tab -> Add Resource -> Add Existing File) such as a .txt or .xml file, then editing this resource file at runtime?  Hopefully this would allow any user (including windows "Standard Users") to edit this resource file.  I tried to implement this but couldn't figure out how.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
eeyo

ASKER
You can resort to the old INI file approach, or something similar. I use an XML file stored in the Roaming\<NameOfMyProgram>, which seems to work fine.
Scott, was this for user or application scope data?
eeyo

ASKER
While there is no perfect solution to this, this may be the best one for now:
Environment.SpecialFolder.CommonApplicationData (C:\ProgramData\ in Win 10)
It still requires the user to have admin rights, unfortunately.