更新时间:2022-01-19 22:25:15
从它的声音来看,您希望在构建文件路径时使用 Application.StartupPath
,因此类似于以下内容;
From the sounds of it you want to be using Application.StartupPath
when constructing your file path so something along the lines of;
System.IO.Path.Combine(Application.StartupPath, "myfile.txt");
如果您想将当前目录设置为正确的目录(尽管我个人建议使用 Application.StartupPath
而不是相信当前目录是正确的),您可以这样做;>
If you want to set the current directory to the right directory (although personally I would recommend using the Application.StartupPath
rather than trust the current directory will be right) you can do this;
System.IO.Directory.SetCurrentDirectory(Application.StartupPath);
至于原因,我曾遇到过这样的情况:打开文件打开对话框,然后导航到另一个位置,然后该位置成为当前目录.
As for why, I've had occasions where you do something like open a file open dialog then navigate to another location, which then becomes the current directory.