将文本文件的内容设置为文本框

时间:2014-08-28 13:56:53

标签: c# winforms file

我正在尝试设置一个打开我项目文件夹中的文本文件。

参见屏幕截图: enter image description here

我的代码如下:

private void loadLog()
{
    string fileName = Path.Combine(Application.StartupPath+"\\Version\\Version.log");
    string temp = File.ReadAllText(@fileName);
    txtVersionLog.Text = temp;
}

我收到错误:

  

未处理的类型' System.IO.DirectoryNotFoundException'发生在mscorlib.dll

     

其他信息:找不到路径的一部分' C:\ Users \ psun \ Documents \ Visual Studio 2012 \ Projects \ EDOrderImport \ EDOrderImport \ bin \ Debug \ Version \ Version.log'。

我的问题是,我是否正确的方向?

2 个答案:

答案 0 :(得分:3)

请务必将文字文件"Copy to output directory" property设置为"始终复制"或者"复制如果更新" (请参阅文件的属性窗格),如果不是,它将保留在您的解决方案目录结构中,并且不会在编译的输出中复制。

答案 1 :(得分:0)

"版本"文件夹应与您的程序/ exe位于同一目录中。因为Application.StartupPath等于您的程序输出路径。

相关问题