FileSaveDialog changing my current working directory path
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开发者_JS百科, 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?
I found a possible answer in the comments on Raymond Chen's excellent blog:
in the class System.Windows.Forms.FileDialog, there is a property 'RestoreDirectory'
Well you could use the Application.StartupPath if you always wanted it to point to the bin directory
精彩评论