0

Hello, I'm trying to open a file from a folder called "Assginement" however, when the program get's released, it might not be in a folder called this. What could I do? I've tried everything.

The other problem is that it creates a file a file, and places it within the same folder, however, it does not know what the foler is going to be called?

Thanks for any help!

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by nick.crane
0

I'm trying to open a file from a folder called "Assginement" however, when the program get's released, it might not be in a folder called this. What could I do? I've tried everything.

If it is in the folder where the application is running from, use Directory.GetCurrentDirectory() static method. Otherwise, you need to use a relative path to the file you are trying to open. Decide now where the directory will be and stick to it. Maybe create a constant and use this whenever you need to access the directory, that way you only need to change it once if you decide to at a later date.

The other problem is that it creates a file a file, and places it within the same folder, however, it does not know what the foler is going to be called?

There are several ways to get the folder name, but I like to use the one I mentioned above - Directory.GetCurrentDirectory();

1

If your user does not have administrative rights then you might find that they cannot write to the file where the program is located.
(A basic User account does not have write access to "Program Files" and its sub-folders.)

You should use the user's data folder to store user specific data files (Application.UserAppDataPath or "User's Application Data Folder" in set-up project).
This is where Properties.Settings stores the application settings by default.
(Note: This path includes the AssemblyFileVersion as part of the folder name. Changes to the FileVersion will change the data folder. )

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.