5

I am developing C#.NET desktop application and I want user to be able to create new database files. I´m new to desktop applications and I don´t really know where is the best place to store those files. I wanted to store them in my application folder but I have read that it´s not the best solution. Should I store them inside C:// or is there some other best practice?

AndyUK
  • 3,933
  • 7
  • 42
  • 44
Somachr
  • 464
  • 1
  • 8
  • 21

2 Answers2

3

You can use AppData\Local. It is a common place for storing application data.

Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
  • If this is unclear to people... the normal windows equivalent of this code is typing %localappdata% into the address bar of your Windows file explorer and pressing enter. See where you end up. – Nyerguds Jan 02 '18 at 09:20
0

This can not easily be answered like this.

  • Is the database LARGE?

A small db can be hidden in ProgramData. THat hardly id goot for possibly terabyte size repositories.

  • Is the user aware there is a database file?

Or is it a "hidden feature" he never sees?

  • Is the database file specific to the application or not?

What happens when you double click?

Should I store them inside C:// or is there some other best practice?

There is best practice. C has NEVER EVER been best practice, so it is not "some other". The only thing more ignorant about the realities of windows would be to store it in the application folder - which by standard is read only for users.

There is a known folders collection and some system calls to find the "true" location for them.

Environment.SpecialFolders enumeration has the places - I trust you can navigate enough documentation to find the rest.

ApplicationData or CommonDocument or something similar may be applicable, but it really depends on the "nature" of it, from a user's perspective.

TomTom
  • 61,059
  • 10
  • 88
  • 148