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!

Recommended Answers

All 2 Replies

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();

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. )

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.