0

我是 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 之前保留一个变量来存储我当前的工作目录?

4

2 回答 2

4

我在Raymond Chen 的优秀博客的评论中找到了一个可能的答案:

在 System.Windows.Forms.FileDialog 类中,有一个属性“RestoreDirectory”

于 2010-12-17T17:06:32.097 回答
1

好吧,如果您一直希望它指向 bin 目录,则可以使用Application.StartupPath

于 2010-12-17T17:01:18.967 回答