有趣生活

当前位置:首页>科技>netcore工程部署Netcore打开指定文件

netcore工程部署Netcore打开指定文件

发布时间:2026-07-25阅读(1)

导读NetCore打开指定文件///<summary>,接下来我们就来聊聊关于netcore工程部署?以下内容大家不妨参考一二希望能帮到您!netcore工程部....

NetCore 打开指定文件 /// <summary>,接下来我们就来聊聊关于netcore工程部署?以下内容大家不妨参考一二希望能帮到您!

netcore工程部署(Netcore打开指定文件)

netcore工程部署

NetCore 打开指定文件

/// <summary>

/// 打开指定目录下的文件

/// </summary>

/// <param name="filePath">文件地址(包含文件名称)</param>

/// <returns></returns>

public static bool OpenFile(string filePath)

{

try

{

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) //windows环境下打开文件

{

filePath = filePath.Replace("&", "^&");

Process.Start(new ProcessStartInfo("cmd", $"/c start {filePath}") { CreateNoWindow = true });

}

else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) //Linux环境下打开文件

{

Process.Start("xdg-open", filePath);

}

else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) //Mac环境下打开文件

{

Process.Start("open", filePath);

}

}

catch (Exception ex)

{

return false;

}

return true;

}

TAGS标签:  netcore  工程  部署  打开  netcore工程部

Copyright © 2024 有趣生活 All Rights Reserve吉ICP备19000289号-5 TXT地图HTML地图XML地图