0

I am almost done with my winforms application. Coming from an asp.net background there are a couple of things, I am not sure how to handle when a user install my exe.

So my application uses filesystem directories to store content files mp3,mp4,(images),.txt&.zip files. The user can add new (content files) to customize these content libraries with in my application.

My question is. What is the best practice for deciding the location of these directories my application relys on. Should the user be asked where to put them, should they go in c:ProgramFiles/MyApplication?

I just want the best way to do this and avoid installation issues Thanks

Paul R
  • 208,748
  • 37
  • 389
  • 560
  • If they are something the user should interact with, then they should go in the documents folder. See vaguely related answer [here](http://stackoverflow.com/questions/35669434/where-should-my-c-sharp-application-write-data-so-that-the-user-can-not-modify-o/35669488#35669488). – Cody Gray - on strike Feb 28 '16 at 13:24
  • Thanks Cody that looks like exactly what I needed know. – Trey Paschal Feb 28 '16 at 13:37
  • Sorry edited this comment a couple time trying to get it right. – Trey Paschal Feb 28 '16 at 13:46
  • None at all. An installer is not required unless you're creating folders that require administrative access. If you're saving into the user's documents or AppData folder, the whole point is that you do not require administrative access. And yes, you can just have logic to create the folder if it doesn't exist. In fact, when accessing a special folder, you would call `Environment.GetFolderPath`, which has an overload that allows you to specify special options, one of which is to create the folder if it does not exist. Naturally, you'll need to handle creating your own *subfolder* in Documents. – Cody Gray - on strike Feb 28 '16 at 13:50
  • I will create a repair utility because the app will ship with libraries that need to be created when the user installs. Sorry I'm figuring out if I hit enter it posts comments prematurely – Trey Paschal Feb 28 '16 at 13:50
  • So I guess that just leaves me at. Is there a proper way to do setup and directory creation logic on install or just set a flag for first run in App settings. I have a txt file that relies on items being in there location because they all work together. I would rather not make these directories apparent to the user if possible. No added temptation to try manually modifying things and breaking stuff. – Trey Paschal Feb 28 '16 at 13:57
  • If you have to write code to repair damage on startup anyway, then you might as well wait until first run to create all the stuff, leveraging the existing code. That feels like bad design to me, intuitively, to depend upon complex data structures being there, but I can't say without knowing more details of your application. – Cody Gray - on strike Feb 28 '16 at 14:00
  • No basically, my application ships with image libraries sample audio, it creates choreography files (.txt) to read back later from images and audio content that the user can manage. I want to keep all of this content in the app so I am using copy file incacse they delete stuff from myPictures ,MyMusic it is still there for the choreo file to find. If not I have a find it dialog to replace the missing content. the only time the user needs to run the repair is if they screw it up or want to set it back to fresh install state. – Trey Paschal Feb 28 '16 at 14:08

1 Answers1

0

If they are something the user should interact with, then they should go in the documents folder. See vaguely related answer here. – Cody Gray

An application run by a user account has the same privileges and permissions as that user. Therefore, there is no way that the application could do something the user couldn't do on his own.

If the data you need to store is intended to be browsed or modified by the user, it should go in Environment.SpecialFolder.Personal.

Otherwise, data should be stored in either Environment.SpecialFolder.ApplicationData (if it should roam with the user account) or Environment.SpecialFolder.LocalApplicationData (if it should not roam with the user, and instead should be limited to the local machine).

Yes, the user can get into these folders and destroy the data. By doing so, they run the risk of breaking your application. You can't secure yourself from yourself.

Develop a "repair" utility that can recover from the damage by recreating the necessary files on startup of your application if necessary.

Community
  • 1
  • 1