Creating a new custom folder on destination PC

BugMan

Well-known member
Joined
Dec 27, 2010
Messages
52
Location
Tallahassee FL
Programming Experience
10+
Back in the olden days, when we chiseled our code onto stone, we could create an application and all support files and subfolders could reside in a main folder on the C: drive. For example, the program and data files could all be in C:\BugMansApp.

Now, if I understand it correctly, the program's .exe file should be under the C:\Program Files\ folder, and the data files that are written must be written elsewhere.

My question is, in the installation setup that I create in VS 2008, can I specify a new folder, say C:\BugMansApp, that I can include in the installation with some .INI like files, dictionaries, text files, etc., where the program can write files to also?

It seems like I can only include text files and such into the canned Windows folders, like PersonalFolder, etc. I realize that I shouldn't hardwire pathnames into my code, it would be nice for the end user to know where the data that he generates is easily (C:\BugMansApp), without having to dig through layers of subfolders.

I see the option to "Add Special Folder" and "Custom Folder" in the deployment menus, but don't understand how to assign "C:\BugMansApp" to the Custom Folder option. Is that the right direction to head to?

Thoughts and advice appreciated!
 
This has all been taken care of for you. Windows provides a folder specifically for programs and applications to store data. It's called ProgramData or ApplicationData, depending on your version of Windows. In your Setup project, you can add a Special Folder in the File System Editor and that is one of the folders you can select. Your installer will always put your folders/files in the right place, regardless of the Windows version. In code, you can use Environment.GetFolderPath or My.Computer.FileSystem.SpecialDirectories.
 
This has all been taken care of for you. Windows provides a folder specifically for programs and applications to store data. It's called ProgramData or ApplicationData, depending on your version of Windows. In your Setup project, you can add a Special Folder in the File System Editor and that is one of the folders you can select. Your installer will always put your folders/files in the right place, regardless of the Windows version. In code, you can use Environment.GetFolderPath or My.Computer.FileSystem.SpecialDirectories.

Thanks jm! Stil missing something... for example, i do the 'Add Special Folder|Custom Folder' menu option, adding "BugMansApp" as the custom folder, it doesn't create the folder but instead just dumps the files into is C:\Program Files (x86). What am I doing wrong? Can I assume that I cannot really create a new folder, with files, at C:\BugMansApp?

Thanks again, your help is very valuable!
 
Don't add a custom folder. As I said in my previous post, it's a standard folder you want: the application data or program data folder.

Under the 'Add Special Folder' option, I only see "Users Application Data Folder" for data folders, and when I add files to this folder is warns that the data won't be seen by all users. Doesn't seem like a good option, I still seem to be doing something wrong or missing something.

I'm using VS Studio 2008 Standard, BTW. Thanks for your patience, jm.
 
My apologies. I was sure that both the user and common application data folders were listed but I haven't created a Setup project for some time. Apparently you do need to create a custom folder:
If someone do the same, don't forget the [] brackets, if you do so the folder showed up under the TargetDir folder. I also set the Property property to COMMONAPPDATAFOLDER.

Name: Common Application Data Folder
AlwaysCreate: false
Condition:
Default Location: [CommonAppDataFolder]
Property: COMMONAPPDATAFOLDER
Transitive: false
 
My apologies. I was sure that both the user and common application data folders were listed but I haven't created a Setup project for some time. Apparently you do need to create a custom folder:

No problem! I'm grateful for your help. I added the custom folder [CommonAppDataFolder] to the Setup and added a text file sample that would be distributed with the app. It did get installed, though just showed up in 'C:\Program Data\' folder. While this is certainly a step in the right direction, I would think that these files would really need to go into a folder like 'C:\Program Data\BugMansApp\', wouldn't it? I see folders there from lots of other software applications, and imagine I should do the same... but how?

Thanks again.
 
Once you've added the special folder to the file system editor, you are free to add subfolders to it. That's how you add a folder for your "company" and a folder for your app below that.
 
Once you've added the special folder to the file system editor, you are free to add subfolders to it. That's how you add a folder for your "company" and a folder for your app below that.

Awesome. That works nicely. In the Properties window: DefaultLocation [CommonAppDataFolder]\BugMan\BugMansApp
That creates my company folder and a folder for that application, and puts my distribution files into that folder.

Now the really dumb question... how do I read/write to that folder using the standard folder? I've tried:

VB.NET:
        Dim ioFile As New StreamReader([CommonAppDataFolder] & "\BugMan\BugMansApp\Test.txt")
        Dim dummy$
        Dummy = ioFile.ReadLine()

but get the error message: "Name 'CommonAppDataFolder' is not declared."

Almost there... thanks!
 
Always check what has already been posted. From post #2:
jmcilhinney said:
In code, you can use Environment.GetFolderPath or My.Computer.FileSystem.SpecialDirectories.
In your case, you would use the first option because the second adds a subfolder for version. The SpecialFolder value will be CommonApplicationData.
 
My question is, in the installation setup that I create in VS 2008, can I specify a new folder, say C:\BugMansApp, that I can include in the installation with some .INI like files, dictionaries, text files, etc., where the program can write files to also?
Common app data folder as mentioned in this thread would not be a good place for this, because only admins can write here (in elevated mode I can imagine). Readonly data files for all users may be put here, or as application resources. Writable files for user settings should be separate for each user (My.Settings is a good start). Writable files common to all users may be put in CommonDocuments folder or subfolder there.

Much has been done in the Window OS to protect both the system and each user account from less privilegied users (let alone themselves). So we end up with
  • various separate folders for each application per user,
  • common folders for each application (where only admin users can write, to prevent less priv users to mess up for all users),
  • a few common folders per user like MyDocuments/Personal, MyMusic, MyPictures etc (typically in c:\users\<User>), and
  • a few common for all users like CommonDocuments, CommonMusic, CommonPictures etc (typically in c:\users\Public).
For interactive user in Explorer these also show up by relevance from root node 'Desktop' to:
- <User>
- Public
- Computer
- Network, etc.
 
Common app data folder as mentioned in this thread would not be a good place for this, because only admins can write here (in elevated mode I can imagine). Readonly data files for all users may be put here, or as application resources. Writable files for user settings should be separate for each user (My.Settings is a good start). Writable files common to all users may be put in CommonDocuments folder or subfolder there.

Hmmm... I was under the impression that common app data was read/write for all users. I guess I must never have actually tested that fact. It must never have actually been an issue or I guess I'd have found out before now. Sorry for the misdirection.
 
Always check what has already been posted. From post #2:In your case, you would use the first option because the second adds a subfolder for version. The SpecialFolder value will be CommonApplicationData.

Believe me jm, I try! And I did see your post, but just did not understand it. I'm new to writing to these standard folders from code, and need example codes. I do appreciate your time taken to help us rookies.
 
Believe me jm, I try! And I did see your post, but just did not understand it.

I said:
In code, you can use Environment.GetFolderPath
Firsth thing? Search for the key words:

Environment.GetFolderPath - Google Search

First match is the MSDN documentation.

Environment.GetFolderPath Method (System)

From there you get an explanation and examples. It's not that hard to pull the keywords out of my posts because I always use the correct terminology (as far as I can) and I always use the correct casing for type and member names. If you research those keywords, it should generally be relatively easy to take at least the next step.
 
I said:Firsth thing? Search for the key words:

From there you get an explanation and examples. It's not that hard to pull the keywords out of my posts because I always use the correct terminology (as far as I can) and I always use the correct casing for type and member names. If you research those keywords, it should generally be relatively easy to take at least the next step.

I see. My apology for the inconvenience.
 
Back
Top