C# System.ComponentModel.Win32异常进程。启动

C# System.ComponentModel.Win32异常进程。启动,c#,.net-core,C#,.net Core,我正在做一个项目,它使用一个网站的api来做一些事情。它将数据保存在一个文本文件中,我希望它在程序结束时打开该文件。我使用System.Diagnostics.Process.Start(myFile),但它会引发异常: Unhandled exception. System.ComponentModel.Win32Exception (13): Permission denied at System.Diagnostics.Process.ForkAndExecProcess(Strin

我正在做一个项目,它使用一个网站的api来做一些事情。它将数据保存在一个文本文件中,我希望它在程序结束时打开该文件。我使用System.Diagnostics.Process.Start(myFile),但它会引发异常:

Unhandled exception. System.ComponentModel.Win32Exception (13): Permission denied
   at System.Diagnostics.Process.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)
   at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start(String fileName)
   at ESEL_Scraper_2._0.Program.Main(String[] args) in /home/af2111/Schreibtisch/Coding/C#/ESEL Scraper 2.0/Program.cs:line 72
我的代码:

使用系统;
使用System.Linq;
使用系统诊断;
使用系统线程;
Net系统;
使用System.IO;
使用Newtonsoft.Json;
名称空间ESEL__2._0
{
类MyJsonType
{
公共字符串标题{get;set;}
公共字符串标记{get;set;}
公共字符串类别{get;set;}
公共字符串位置{get;set;}
公共int id{get;set;}
公共字符串startdatetime{get;set;}
}
类根{public MyJsonType[]termine{get;set;}}
班级计划
{
静态void Main(字符串[]参数)
{
int queryResults=0;
Console.WriteLine(“您希望返回多少天?”);
字符串userInput=Console.ReadLine();
int result=Int32.Parse(userInput);
WriteLine(“您想要搜索什么?”);
字符串userInput2=Console.ReadLine();
秒表秒表=新秒表();
秒表。开始();
for(int j=0;j0){
使用(System.IO.StreamWriter)文件=
新System.IO.StreamWriter(@“eselStats.txt”,true))
{
WriteLine($“{userInput2}:{queryResults}Ergebnisse.”);
System.Diagnostics.Process.Start(“eselData.txt”);
}    
}
}
}
}
我的文件确实被创建了,看起来应该没有问题。
有人知道如何修复吗?

当您尝试执行不可执行的文件时,Linux系统会显示
权限被拒绝。我认为您不想执行文本文件。您更希望使用默认文本编辑器打开它

我不确定这是否适用于所有Linux系统,但至少在Windows上,您可以通过将
ProcessStartInfo.UseShellExecute
设置为
true
来实现这一点。默认情况下,它在.NET Core中被禁用。见微软的

示例代码:

var startInfo = new ProcessStartInfo("eselData.txt")
{
    UseShellExecute = true
};
Process.Start(startInfo);

当您试图执行一个不可执行的文件时,Linux系统显示
权限被拒绝
。我认为您不想执行文本文件。您更希望使用默认文本编辑器打开它

我不确定这是否适用于所有Linux系统,但至少在Windows上,您可以通过将
ProcessStartInfo.UseShellExecute
设置为
true
来实现这一点。默认情况下,它在.NET Core中被禁用。见微软的

示例代码:

var startInfo = new ProcessStartInfo("eselData.txt")
{
    UseShellExecute = true
};
Process.Start(startInfo);

拒绝访问
如果路径正确,则您可能没有此路径的权限,为了进行测试,请在管理员模式下重新运行Visual Studio并再次检查。我在linux上使用vs代码,是否只运行sudo dotnet?
拒绝访问
如果路径正确,则您可能没有此路径的权限,为了进行测试,请在管理员模式下重新运行Visual Studio并再次检查。我在linux上使用vs代码,是否只运行sudo dotnet?@af2111如果适用,您可以将此答案标记为解决方案吗?@af2111如果适用,您可以将此答案标记为解决方案吗?