FileSaveDialog 更改我当前的工作目录路径
我是 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 之前保留一个变量来存储我当前的工作目录?
I am new to winforms and facing one problem in my application. I am trying to show the user to save a file using SaveFileDialog control on my form. But as soon as the user chooses his directory and saves his file, my next code which uses Directory.getCurrentDirectory() fails to point to my working directory. It seems that SaveFileDialog is causing problem here.
For eg:- I have these lines of code -
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.)
Is there any solution for this so that my current working directory does not get changed or should I keep a variable to store my current working directory before saveDialog is used?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在 Raymond Chen 的优秀博客的评论中找到了可能的答案:
I found a possible answer in the comments on Raymond Chen's excellent blog:
那么你可以使用 Application.StartupPath 如果你一直希望它指向 bin 目录
Well you could use the Application.StartupPath if you always wanted it to point to the bin directory