Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

My program needs to write configuration files and some data files somewhere. I know that writing files to my program's .EXE path (which will be within C:\Program Files) can cause issues related to permissions. So, I'm doing this:

ProgramDataPath = System.Windows.Forms.Application.CommonAppDataPath

ProgramDataPath is a global string within my program, and whenever a function wants to read/write configuration and data files, it'll use this as the base path.

Well, my first question is: Is this correct? Is that the right place for my program to write those files? I don't want them to be user-specific. I'd like them to be for all users.

Assuming that it is the right place, this path is always like this:

C:\ProgramData\MyCompany\MyProgram\Version\

And so the files will always be written under the program's version number. But what if I want to use those files for all versions of my program? Can I simply edit the string and remove the "Version\" from it, and write everything directly under C:\ProgramData\MyCompany\MyProgram\ ? Are there any problems with that?

Thanks in advance!

What I have tried:

I've tried writing files to System.Windows.Forms.Application.CommonAppDataPath and it has been working great. However, they're being written under the program's version number.
Posted
Updated 27-Feb-18 20:45pm
Comments
PIEBALDconsult 27-Feb-18 22:38pm    
Sounds OK to me.

I'd suggest to read this: Where should I store my data?[^]
 
Share this answer
 
Comments
phil.o 28-Feb-18 7:56am    
I just saw this question and it was the first answer which came to my mind.
My 5.
Maciej Los 28-Feb-18 7:58am    
Thank you ;)
Tesouro 28-Feb-18 11:19am    
Well, I had read that before when searching for a solution, and the thing that made me not want to use that solution was that the GUID is a long ugly value, and I'd like for the user to be able to see the MyCompany\MyProgram on the path, and feel comfortable making changes there as well if necessary.

But still, by the answers given I'd assume it'd be indeed ok for me to simply write files under C:\ProgramData\MyCompany\MyProgram\ instead of C:\ProgramData\MyCompany\MyProgram\Version\ , right? (Just making sure)
Maciej Los 28-Feb-18 11:31am    
If - in your opinion - using GUID is ugly, i'd suggest to separate places where an application stores settings and user data.
Well, you've been warned, so the choice is yours.
Tesouro 28-Feb-18 11:57am    
That's a good advice. Thanks!
To solve your problem you can use this:
create your 'own' data folder in the 'C:\ProgramData\' folder with a name of your choice:
VB
Dim MyDataFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\FolderName\"

create once in your application the data folder:
VB
Directory.CreateDirectory(MyDataFolder)

and save you data with something like:
VB
File.WriteAllText(MyDataFolder + "Mydata.inf", MyData)
 
Share this answer
 
Comments
Tesouro 28-Feb-18 11:22am    
It's a possibility. However, for some reason my program always create the folder automatically with the Company Name \ Program Name \ Version. Maybe it's an assembly setting that could be disabled.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900