-3

My program must produce files from some given data. I'm dealing with PDFs and Excel documents. How do I allow the user to set the directory where the files will be saved? I'm not referring to SaveFileDialog where the user must choose the directory every time. I want the files to automatically be saved to the directory previously specified by the user. Something to this effect:

YTD

Most immediate solution I can think of is to store the directory in a file and read it every time a file is to be saved.

I also read about Properties.Settings.Default.Save(), but is it relevant to my case?

Donovan Keating
  • 1,715
  • 3
  • 17
  • 27

2 Answers2

2

Use FolderBrowserDialog to get the folder... https://msdn.microsoft.com/en-us/library/system.windows.forms.folderbrowserdialog(v=vs.110).aspx

Get the folder's path.

folderName = folderBrowserDialog1.SelectedPath;

Then go into your project properties (Project menu > Project Name Properties), and click the settings tab. Add a new setting with a name of your choice, like SaveLocation with the type of string. Then you can save it like so...

Settings.Default["SaveLocation"] = folderName;
Properties.Settings.Default.Save();

And then, obviously, retrieve it like so...

string saveLocation = Settings.Default["SaveLocation"]

Read more about saving application settings here: https://msdn.microsoft.com/en-us/library/a65txexh.aspx

bwoogie
  • 4,339
  • 12
  • 39
  • 72
-1

You may care to use the registry to store information between sessions. This will require that you have admin privileges. Since this is winform it may be.

user1497197
  • 81
  • 2
  • 10