当我试图在某个存储库中打开最近生成的文本文件时,我收到了一个错误。
“参数2:不能从System.IO.FileInfo转换为'string'”
错误在"newestFile“下划线。
var directory = new DirectoryInfo(Program.resultsFolder);
var newestFile = directory.GetFiles().OrderByDescending(f => f.LastWriteTime).First();
Process.Start("notepad.exe", newestFile);有谁知道为什么会发生这种事,我怎样才能解决它?
发布于 2015-11-09 02:24:31
这是有意义的,因为GetFiles返回一个FileInfo对象数组,您将选择第一个对象。除了名称之外,FileInfo还包含更多关于该文件的信息。
如果要访问文件的路径,则必须使用正确的属性。
假设该文件是txt文件,而记事本是该类型的默认应用程序,则只需使用FullName。
Process.Start(newestFile.FullName);发布于 2015-11-09 02:24:23
Process.Start以两个字符串作为参数。您的原始代码是fileinfo类型。需要转换为字符串
var newestFile = directory.GetFiles().OrderByDescending(f => f.LastWriteTime).First().ToString();https://stackoverflow.com/questions/33601526
复制相似问题