简体   繁体   中英

WPF C# Opening files in multiple directories

I have 3 open file buttons which open a file open dialog, whenever one file is opened the starting directory for the next button is always the same as the last button that was used.

I need to be able to have each button open only the last directory that it was associated with, not what the last button opened was associated with.

How can make each dialog open in the directory that that specific dialog was opened in last?

Example, I have 3 buttons i want to open in the following order:

Btn1 Open File in dir C:\temp\1 then
Btn2 Open File in dir C:\temp\1 then change to C:\temp\2
Btn3 Open File in dir C:\temp\2 then change to C:\temp\3

Btn1 Open File in dir C:\temp\1 NOT in C:\temp\3

declare some private fields in your class:

string startLocationForDialog1 = "C:\";
string startLocationForDialog2 = "C:\";
string startLocationForDialog3 = "C:\";

Then in your methods, when you create the open file dialog, set the starting location to the value of the corresponding variable.

After the file is selected, save the location of the file (without the file name) in the corresponding variable. Next time you press the same button, you use that variable which contains the last location from which a file was selected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM