代码如下:
OpenFileDialog fDialog = new OpenFileDialog();
fDialog.Title = "Select script to load...";
fDialog.Filter = "Text Files|*.txt";
fDialog.ShowDialog();
string text = File.ReadAllText(Path.GetFullPath(fDialog.FileName));
if (text.Length > 0)
{
LuaCArea.Text = text;
}
我收到错误:
路径不是合法形式。
有什么想法吗?
答案 0 :(得分:3)
等待OpenFileDialog
结果dud,不要使用Path.GetFullPath
OpenFileDialog fDialog = new OpenFileDialog();
fDialog.Title = "Select script to load...";
fDialog.Filter = "Text Files|*.txt";
if(fDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
LuaCArea.Text = File.ReadAllText(fDialog.FileName);
}