Reputation: 31
I'm nearly done creating my first app using Windows Forms and C#. It is a simple budgeting app that relies on writing to a text file for persistent storage and to a .csv file for a spending log, so that the user can open the .csv with excel to do some easy analysis. In my program, the file path used for these is just @"AccountStorage.txt."
My debug and release builds have no problem, and those files are easily accessible within the application folder.
However, when I use the publish wizard and build and install that way, those files are hidden in %appdata%/apps/2.0/(random numbers and letters)
. Is there any way to stop Visual Studio from hiding those files there and instead putting them in an easily accessible place?
Thanks!
Upvotes: 1
Views: 479
Reputation: 1892
Just to complement the answers, it´s important to utilize a SpecialFolder to save your data IF YOUR APP does not run in "Admin Mode".
If you run your application "as Invoked" (not as Admin), when you will try to save data in the PROGRAM-FILES folder you, probably, will get an error - WIndows sometimes deny the Write in this area, specially if you utilize "full-path" addressing (like "c:\ProgramFiles\MyApp\Somefile.txt").
So, could be interesting to achieve data as Vlad recommend, or in my advise, using some COMMON or USER area. The difference between both is that in a COMMON area, all logins will see the file, while in USER area, each login will see only its own file.
The syntax is:
Common Area:
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) & "\YourAppName"
USer Area
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\YourAppName"
Also, you have other areas to do it (see all options of Environment.SpecialFolder) and you may also utilize PATH.COMBINE to create the link I shown above in a litteral mode (adding the slash and app name).
Good luck
Upvotes: 0
Reputation: 31
Consider using "My Documents" for any personal documents created from an app which a user wants easy access to. You can get that path like so: System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "MyAppName");
Vlad's answer was great. Sorry my rep is too low to mark it as the right one!
Upvotes: 1