Click here to Skip to main content
15,663,632 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
My app needs to create files at runtime. I made an installer but Windows don't let the program write in the installation folder.How do I solve this problem? Everything needs to be programmatically 'cause the program will be installed in any pc. I use C# 4.0
Posted

If your application needs to create files at runtime you need to put them in different locations depending on the usage of the files.
If the file is for the application to use regardless of the user use the path returned by;
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)

Add a folder for your application to the path returned by the above code and store the files in there.

If the file is user specific use the path returned by;
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

Again add a folder for your application to the path returned by the above code and store the user specific files in there.

Generally you can get away with only using the above path for user specific data but there is another path which can be used which is;
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)

The difference between the two is that the first one is used with roaming users on a domain and is replicated onto other computers a user logs onto where the second one is user data that is specific to a single machine.

Why do you have to do it this way, because Microsoft increased security on the Program Files directory so that the only files that are stored there were put there by an installer.
 
Share this answer
 
And have you perhaps just blindly cast about and stumbled on the Folder class? :rolleyes:

A Windows installer can create a folder structure during an installation.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900