Environment.CurrentDirectory 与 Application.StartupPath

原来用C#写文件的时候都不喜欢用路径,例如,我会用

FileStream fsEncrypted = new FileStream("data.xml", FileMode.Create, FileAccess.Write);
这样在程序所在目录建一个文件,最进发现在用 OpenFileDialog 的时候会改变默认路径,这样我的文件就不知道建到哪儿去了,后来就用了 Environment.CurrentDirectory ,MSDN 上的解释是 
Gets and sets the fully qualified path of the current directory; that is, the directory from which this process starts
我以为这样就可以了,结果试了还是不行,原来 Environment.CurrentDirectory  也受 OpenFileDialog 的影响,
实在没办法了,又查,这次用了  Application.StartupPath 
好了,这下存的文件不会乱跑了。
原文地址:https://www.cnblogs.com/icehong/p/39155.html