dbilancione
New member
- Joined
- Jul 17, 2023
- Messages
- 3
- Programming Experience
- Beginner
Hi everyone,
I am new to C#/VSTO. I used to build Excel application using VBA but I want to move to VSTO. I started converting an application I recently built using VBA.
Using the OpenFileDialog class I wanted to set an InitialDirectory property to "Desktop", which I successfully did, but I wish to restore the last opened path (using the RestoreDirectory property if the user had already navigated to a different path.
Is there a way to test if there is a directory to restore as initial directory else set the "Desktop" as initial directory?
Something like
Many thanks for your suggestions!
I am new to C#/VSTO. I used to build Excel application using VBA but I want to move to VSTO. I started converting an application I recently built using VBA.
Using the OpenFileDialog class I wanted to set an InitialDirectory property to "Desktop", which I successfully did, but I wish to restore the last opened path (using the RestoreDirectory property if the user had already navigated to a different path.
Is there a way to test if there is a directory to restore as initial directory else set the "Desktop" as initial directory?
Something like
C#:
OpenFileDialog fdlg = new OpenFileDialog();
fdlg.Title = "Import";
if fdlg.RestoreDirectory(path) not set
fdlg.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
fdlg.Filter = "Excel Files (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm|All Files (*.*)|*.*";
fdlg.FilterIndex = 1;
fdlg.Multiselect = true;
fdlg.RestoreDirectory = true;
if (fdlg.ShowDialog() == DialogResult.OK)
{
foreach (String file in fdlg.FileNames)
{
MessageBox.Show(file);
}
}
}
Many thanks for your suggestions!