![](/img/trans.png)
[英]c# retrieve file/folder path from selected file/folder in Context Menu Windows Explorer
[英]Get file from Windows Explorer "open with" Context Menu C# Wpf
当用户选择在 c# 中使用 wpf 应用程序打开“.txt”文件并在文本框中显示 .txt 文件中的文本时,我如何从 Windows Explorer 获取 txt 文件?
我会在这里写下完整的答案,以便您接受。
解决办法是:
根据这个答案得到右键文件的路径。
使用System.IO.File.ReadAllText读取文件内容
通过设置其 Text 属性显示文本框中的文本。
在代码中,这将用于 richtextbox
public MainWindow()
{
InitializeComponent();
try
{
string[] args = Environment.GetCommandLineArgs();
richtextbox.Document.Blocks.Clear();
richtextbox.Document.Blocks.Add(new Paragraph(new Run(File.ReadAllText(args[1]))));
}
catch
{
}
}
和正常的文本框
public MainWindow()
{
InitializeComponent();
try
{
string[] args = Environment.GetCommandLineArgs();
textbox.Text = File.ReadAllText(File.ReadAllText(args[1]));
}
catch
{
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.