How to install a file in app data in setup project (C#)
11,572
Solution 1
- Right-click on the project and select View -> File System
- 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
- Select the newly added folder form the treeview and create any sub-folder structure you need
- Finally select your destination folder, right-click, Add -> File and select the .mddb file.
Solution 2
Right click on your Setup project -> View -> File System. Then you could add a custom folder and set its default location to [CommonAppDataFolder]
:
Then add your database file to this folder.
Solution 3
Just for completeness, here is the official documentation for changing the folders: https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/716bxh4e(v=vs.100)
- 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.
- On the Action menu, point to Add Special Folder, and then click Custom Folder. The new folder is highlighted in the folder list.
- Type a name for the custom folder. For example, to target the Temp folder, type "Temp Folder".
- 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://docs.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.
Author by
Mike Bryant
Updated on June 20, 2022Comments
-
Mike Bryant almost 2 years
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?
-
Mike Bryant over 12 yearsI 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/ subfolders
-
Mike Bryant over 12 yearsMy database file is not in there
-
Mike Bryant over 12 yearsI've viewed the folder by modified date and there's nothing new
-
Mike Bryant over 12 yearsIt works, in program data folder but not in app data folder. Thanks for your help
-
Mike Bryant over 12 yearsIt does work I thought that when i right clicked and install that it automatically re generated the setup file but no.
-
Andreas over 3 yearsYou 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.
-
Ksdmg over 3 years@Andreas I have added the related information as you suggested, to make the answer complete.