How to install a file in app data in setup project (C#)
Asked Answered
S

3

9

I want to install my database to a separate folder (@ C:\Users\User1\AppData\Roaming\Company1\database.mdb)

I'm using a C# setup project.

How can I do it?

Spasm answered 2/12, 2011 at 10:1 Comment(0)
A
9
  1. Right-click on the project and select View -> File System
  2. in the new File System screen, right-click the root node (File System on target Machine) and select Add Special Folder -> User's Application Data Folder
  3. Select the newly added folder form the treeview and create any sub-folder structure you need
  4. Finally select your destination folder, right-click, Add -> File and select the .mddb file.
Anhwei answered 2/12, 2011 at 10:14 Comment(2)
I tried that but got File '<file>' should not be installed into a User's Profile folder because it may not be available to all users No sign of my database anywhere in the app data folder/ subfoldersSpasm
It does work I thought that when i right clicked and install that it automatically re generated the setup file but no.Spasm
M
8

Just for completeness, here is the official documentation for changing the folders: https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/716bxh4e(v=vs.100)

  1. To add a custom folder that targets a predefined Windows folder In the folder list of the File System Editor, select the File System on Target Machine node.
  2. On the Action menu, point to Add Special Folder, and then click Custom Folder. The new folder is highlighted in the folder list.
  3. Type a name for the custom folder. For example, to target the Temp folder, type "Temp Folder".
  4. In the Properties window, select the DefaultLocation property and enter the Windows Installer system folder property for the folder you wish to target. For example, the property for the Temp folder is [TempFolder]. For a list of system folder properties supported by Windows Installer, see System Folder Properties.

Here is a list of all folder properties: https://learn.microsoft.com/en-us/previous-versions//aa372057(v=vs.85)?redirectedfrom=MSDN

Property Description
AdminToolsFolder The full path to the directory that contains administrative tools.
AppDataFolder The full path to the Roaming folder for the current user.
CommonAppDataFolder The full path to application data for all users.
CommonFiles64Folder The full path to the predefined 64-bit Common Files folder.
CommonFilesFolder The full path to the Common Files folder for the current user.
DesktopFolder The full path to the Desktop folder.
FavoritesFolder The full path to the Favorites folder for the current user.
FontsFolder The full path to the Fonts folder.
LocalAppDataFolder The full path to the folder that contains local (nonroaming) applications.
MyPicturesFolder The full path to the Pictures folder.
PersonalFolder The full path to the Documents folder for the current user.
ProgramFiles64Folder The full path to the predefined 64-bit Program Files folder.
ProgramFilesFolder The full path to the predefined 32-bit Program Files folder.
ProgramMenuFolder The full path to the Program Menu folder.
SendToFolder The full path to the SendTo folder for the current user.
StartMenuFolder The full path to the Start menu folder.
StartupFolder The full path to the Startup folder.
System16Folder The full path to folder for 16-bit system DLLs.
System64Folder The full path to the predefined System64 folder.
SystemFolder The full path to the System folder for the current user.
TempFolder The full path to the Temp folder.
TemplateFolder The full path to the Template folder for the current user.
WindowsFolder The full path to the Windows folder.
WindowsVolume The volume of the Windows folder.

When using them, make sure to use the square brackets [] around the property names.

Monafo answered 13/10, 2020 at 9:13 Comment(2)
You really should add the most relevant parts of your linked resources to your answer. Web resources change sooner or later and might not be available any longer. This is very true for Microsoft pages.Paving
@Paving I have added the related information as you suggested, to make the answer complete.Monafo
F
6

Right click on your Setup project -> View -> File System. Then you could add a custom folder and set its default location to [CommonAppDataFolder]:

enter image description here

Then add your database file to this folder.

Fruitless answered 2/12, 2011 at 10:12 Comment(3)
My database file is not in thereSpasm
I've viewed the folder by modified date and there's nothing newSpasm
It works, in program data folder but not in app data folder. Thanks for your helpSpasm

© 2022 - 2024 — McMap. All rights reserved.