通过单击TXT文件,读取TXT文件并在消息框中显示该文件中的所有文本。 [英] Read TXT file and show all text in that file in message box by Clicking on TXT file.
问题描述
嗨亲爱的
我想创建一个代码,当我点击Windows资源管理器中的任何文本文件时,程序会读取所有单击的TXT文件中的数据,并在c#的massegebox中显示所有文本。 />
我想知道的是,如何将.txt文件路径发送到程序,或者如何在程序中检测.TXT文件路径。我已经完成了其他部分。
请帮助我。
Hi dears
I want to create a code that when I click on Any text file in windows explorer the program read all data in clicked TXT file and shows all text in massegebox in c#.
The point that I want to know it that how can I sent the .txt file path to the program or how can I detect the .TXT file path in my program. I have done other parts.
Please help me.
推荐答案
您可以在资源管理器中将项目添加到上下文菜单(右键单击)。有几种方法可以做到这一点
将上下文菜单添加到Windows资源管理器 [ ^ ]
.NET Shell Extensions - Shell Context Menus [ ^ ]
或将您的程序添加到发送到文件夹并捕获命令行 [ ^ ]
You can add items to the context menu (right click) in Explorer. There are a couple of ways of doing that
Add a context menu to the Windows Explorer[^]
.NET Shell Extensions - Shell Context Menus[^]
Or Add your program to the "Send To" folder and capture the command line[^]
我想以下将会有所帮助。
I guess the following will do the trick.
using System;
using System.IO;
using System.Windows.Forms;
namespace TXT2MsgBox
{
static class Program
{
static void Main(string[] args)
{
if (args.Length > 0)
{
FileInfo fi = new FileInfo(args[0]);
if (fi.Extension.Equals(".txt", StringComparison.InvariantCultureIgnoreCase))
{
string txtContent;
using(TextReader tr = new StreamReader(args[0]))
{
txtContent = tr.ReadToEnd();
}
MessageBox.Show(txtContent, fi.Name);
}
}
}
}
}
你是什么要做的就是将此可执行文件放在发送到文件夹中。更方便的做法:
WinKey + R
类型:shell:sendto
按enter
在这里复制应用程序或在这里放一个快捷方式
我希望这会有所帮助。
What you have to do is putting this executable in the 'Send To' folder. the easiers way to do this:
WinKey + R
TYPE: shell:sendto
Press enter
Copy the application here or put a shortcut here
I hope this helps.
这篇关于通过单击TXT文件,读取TXT文件并在消息框中显示该文件中的所有文本。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!