我是 winforms 的新手,在我的应用程序中面临一个问题。我试图向用户展示使用表单上的SaveFileDialog控件保存文件。但是一旦用户选择了他的目录并保存了他的文件,我下一个使用Directory.getCurrentDirectory()的代码就无法指向我的工作目录。似乎 SaveFileDialog 在这里引起了问题。
例如:-我有这些代码行-
MessageBox.Show( Directory.GetCurrentDirectory( ) ); // output: C:\TestSamples\TestApp\Bin\Debug
fdSave.ShowDialog( ); // fdSave is SaveFileDialog control which will show to save file
MessageBox.Show( Directory.GetCurrentDirectory( ) ); //output: C:\Program files\outputDir (This is the path chosen by user to save file in previous saveDialog.)
是否有任何解决方案,以便我当前的工作目录不会被更改,或者我应该在使用 saveDialog 之前保留一个变量来存储我当前的工作目录?