LoginSignup
4
3

More than 1 year has passed since last update.

Windowsの既定のアプリでファイルを開く

Posted at

やりたいこと

既定のアプリを使用してファイルを開きたい。

以下のようにProcess.Startの引数にファイルパスを渡すと既定のアプリで起動できる場合もあるが、.txtなど拡張子によっては起動できない場合がある。

System.Diagnostics.Process.Start("ファイル.log");

方法

ProcessStartInfoのUserShellExecuteをtrueにしてやると既定のアプリで起動できる。

string filePath = "ファイル.log";

var startInfo = new System.Diagnostics.ProcessStartInfo()
{
    FileName = filePath,
    UserShellExecute= true,
    CreateNoWindow = true,
}
System.Diagnostics.Process.Start(startInfo);
4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3