Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

get default full path of SaveFileDialog?

4 REPLIES 4
Reply
Message 1 of 5
cpicke
1755 Views, 4 Replies

get default full path of SaveFileDialog?

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?

4 REPLIES 4
Message 2 of 5
rossano_praderi
in reply to: cpicke

Hi cpicke,

the last open/saved file paths are stored in this registry Key:

HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Comdlg32\OpenSaveMRU

 

Bregs

Rossano Praderi



--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------
Message 3 of 5
santoshr0114
in reply to: cpicke

Hi,

 

Inventor SaveFileDialog does not actually set the Initial Directory.

If you are working on Events then you can set the Initial Directory when the save event is triggered.

 

I hope you are aware of Project settings in Inventor.

 

Inventor actually picks up the Workspace location from the active project as the Initial Directory to prompt the save dialog.

If nothing is configured then it prompts to "My Documents" or recently browsed document location

 

You can verify the same by configuring your project settings.

 

 

Regards
Santosh
Message 4 of 5
cpicke
in reply to: rossano_praderi

Dear all,

 

The first answer provided by Dshortway is very close to the solution, grazie!!! Unfortunately not quite there: a few points

 

#1) I believe that Windows 7 and later uses PIDL in the registry as ComDlg32\OpenSavePidlMRU, not ComDlg32\OpenSaveMRU. This folder in the registry contains the last opened or saved files, sorted by file extension. For sake of reference, let us consider .csv files. So I can navigate to ComDlg32\OpenSavePidlMRU\csv and therein I find the last 20 opened or saved paths of the .csv files (in binary, not human-readable) and one other variable that contains the order in which these were saved or opened.

 

#2) To make these binary values human-readable is not such a trivial process. After a lot of searching around, I found that a user "CoolSanil" on the MSDN forums provided a solution at the page "How to get PIDL from OpenSavePidlMRU". I slightly adapted his solution so instead of getting the value of key "0", I read the OpenSavePidlMRU\csv\MRUListEx key first to find out which of the other keys is the most recent, then get the value of that key instead.

 

Here's the remaining problem though: The most recent key in the registry corresponds to the .csv file that was last opened or saved by any program, not just Inventor. Somehow, Inventor actually remembers which .csv file was last opened or saved by Inventor itself, which may not necessarily be the last .csv that was saved and opened by any program.

 

Does anybody know how I can tell which of the file paths in OpenSavePidlMRU\csv\[0 through 19] was opened or saved last specifically by Inventor?

Message 5 of 5
rossano_praderi
in reply to: cpicke

Hi Dear,
yes I haven't wrote the "Pill" inside the path, thank you for the correction.


I would like to give you an other "piece" of information, this is an old post but can give you an idea on how to find the solution....

 

http://digital-forensics.sans.org/blog/2010/04/02/openrunsavemru-lastvisitedmru/

 

Bregs

Rossano Praderi



--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report