get default full path of SaveFileDialog?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Dear all,
Within the Inventor API (using Microsoft Visual Studio), how can I get the default path used by System.Windows.Forms.SaveFileDialog, when there is no value assigned to InitialDirectory? The default path is the last location where a file was successfully saved.
To clarify, I don't want to set the default path associated with SaveFileDialog; I want to get the default path associated with SaveFileDialog, and I would like to get the default path without saving a file. The reason is that I want to print this path at initialization to a text field in a user interface dialog box before the user ever saves a file.
The relevant code snippet is:
SaveFileDialog sfd = new SaveFileDialog();
sfd.AddExtension = true;
sfd.DefaultExt = "txt";
sfd.FileName = "output.txt";
sfd.RestoreDirectory = false;
string str0 = sfd.InitialDirectory;
DialogResult dr = sfd.ShowDialog();
if (dr == DialogResult.OK)
{
string str1 = sfd.FileName;
}
If I execute this code and only click OK in the dialog box, I find that str0 is blank and that str1 is equal to the full path that I want. However, as said above, I would like to somehow retrieve the full path without executing SaveFileDialog. I know that the full path must be stored somewhere within the application because if I save to a new directory or a new location, it is remembered even after Inventor is closed and reopened!
Please note:
#1) The full path is not anywhere in the (Windows 7) registry; I tested this with a unique folder name and then attempted to search for it in the entire registry; could not find it.
#2) The path is not System.Environment.CurrentDirectory.ToString(); this is instead the path to the directory that contains the last .ipt file opened through the inventor GUI and is definitely not the same as the directory containing the last successfully saved file.
#3) The path is not InventorBaseButton.InventorApplication.ActiveDocument.FullFileName; this is instead the path to the .ipt file currently open and is different to both the directory in #2) and the directory containing the last successfully saved file.
Does anybody know how the default path used by System.Windows.Forms.SaveFileDialog can be retrieved?