Link to home
Create AccountLog in
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.
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

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.
Avatar of eeyo
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
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of 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 ...
Avatar of 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?
Only other thing I could suggest would be either (a) a database or (b) a Public Document folder for your xml file.
Avatar of 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.
Avatar of 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?
Avatar of 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.