Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用记事本打开嵌入式字符串资源?_C#_.net_Embedded Resource_Shellexecute - Fatal编程技术网

C# 如何使用记事本打开嵌入式字符串资源?

C# 如何使用记事本打开嵌入式字符串资源?,c#,.net,embedded-resource,shellexecute,C#,.net,Embedded Resource,Shellexecute,我在参考资料中添加了help.txt文件作为文本文件,如下所示: private void helpButton_Click(object sender, MouseEventArgs e) { System.Diagnostics.Process.Start(myProject.Properties.Resources.help); } 它不起作用,然后我试着这样做: private void helpButton_Click(object sender, MouseEventArg

我在参考资料中添加了help.txt文件作为文本文件,如下所示:

private void helpButton_Click(object sender, MouseEventArgs e)
{
    System.Diagnostics.Process.Start(myProject.Properties.Resources.help);
}
它不起作用,然后我试着这样做:

private void helpButton_Click(object sender, MouseEventArgs e)
{
    System.Diagnostics.Process.Start(@"help.txt");
}
它也不起作用,但它是这样起作用的:

private void helpButton_Click(object sender, MouseEventArgs e)
    {
        System.Diagnostics.Process.Start(@"C:\Projects\CourceWork\Resources\help.txt");
    }

问题是我不想处理这个硬核定义的路径,我该怎么办?

您似乎想用与
.txt
文件关联的默认程序打开一个嵌入式资源,该文件通常是记事本。不幸的是,记事本无法读取嵌入的资源。因此,您需要提取资源并将其保存为磁盘上的文件,然后用该文件打开记事本

var helpFile = Path.Combine(Path.GetTempPath(), "help.txt");
File.WriteAllText(helpFile, myProject.Properties.Resources.help);
Process.Start(helpFile);

或者,您可以创建自己的显示文本的
表单
,在我看来,这是一个更好的解决方案(除非您的帮助文件不容易显示,例如PDF文件)。

如果您想从代码在默认文本编辑器中打开.txt文件,然后,您应该重新考虑将其放在参考资料中,但将其放在项目的同一目录中,或者放在易于检索的目录中,例如MyDocuments