更改扩展名后打开文件

米歇尔·法拉第

我想在更改扩展名后打开文件。扩展名已更改,但找不到要打开的文件,那么我如何找到它?到目前为止我所拥有的:

filePath = openFileDialog.FileName;
File.Move(filePath, Path.ChangeExtension(filePath, ".csv"));
FileStream stream = File.Open(filePath, FileMode.Open);

使用来自的返回值Path.ChangeExtension

filePath = openFileDialog.FileName;
var newFilePath = Path.ChangeExtension(filePath, ".csv");
File.Move(filePath, newFilePath);
FileStream stream = File.Open(newFilePath, FileMode.Open);

上面的代码在您的应用程序中打开文件。

如果您希望 Windows Shell 使用 Excel、OpenOffice 等打开文件,您可以通过其他方式执行此操作。

System.Diagnostics.Process.Start(newFilePath);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章