7

My program contains a sql lite db file which my program creates after first run and then stores the data inside updon app usage. The database builds up over a period of time. The db file is created in the installation directory of the program

I have to update the app on a regular basis when there are bugs fixed, so basically I publish a new msi installer, the installer removes old installation files except db file and install new program files.

Some user's do not install it to the default location so in their selected location the db file is not present.

I want to know if it's ok to store data files to some program data folder outside the install dir ? so that every new update of my program can access the data from that program data folder.. ?

Is there any program data directory in windows xp, vista and 7 ? and how to access it in C#/

ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
Ahmed
  • 14,503
  • 22
  • 92
  • 150
  • 1
    This is not a normal kind of deployment, you don't have write access to the directory in which the EXE was installed. UAC puts a stop to that. Files must be stored in an AppData directory. Which solves this problem as well. – Hans Passant Nov 20 '12 at 23:17

3 Answers3

11

Have a look Environment.SpecialFolder Enum to decide about the right place for your data.

I would vote for Recent folder though, here are other options:

  • ApplicationData (Current users roaming profile)
  • CommonApplicationData (All users on local machine)
  • LocalApplicationData (Current user on local machine)

Get the folder of your choice with

Environment.GetFolderPath(Environment.SpecialFolder.xxx))
ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
Lukas Winzenried
  • 1,919
  • 1
  • 14
  • 22
8

It is very dangerous to store user data in the application folder. Not only will the data be destroyed if the user updates or uninstalls your app, but Standard users cannot even write to the app directory.

I typically include a seed database in the application and copy it to a folder in the Environment.SpecialFolder.ApplicationData folder when the application launches. All user data is stored in the copy; if the user uninstalls the application the seed database is deleted but the user data remains. See this SO answer for an example.

Community
  • 1
  • 1
Dour High Arch
  • 21,513
  • 29
  • 75
  • 90
1

You should not store data in the install folder. Try this. The special folders are designed for you to be able to store this kind of data. There is also the Application Settings, which are asy to access and provide an easy way to store user key value pair, Information.

mega6382
  • 9,211
  • 17
  • 48
  • 69
Adam Straughan
  • 2,766
  • 3
  • 20
  • 27