Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Comments
[no name] 28-May-14 9:35am    
Help you with what? What code have you written? What is the problem with your code?

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[^]
 
Share this answer
 
I guess the following will do the trick.

C#
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);
                }
            }
        }
    }
}


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.
 
Share this answer
 
Comments
alireza ghasemi 29-May-14 0:48am    
Thank you very very much Ward
You are Great my friend.
It is very useful way to complete my work.
But is there any way that When I Double-Click on TXT file it opens by this application?
alireza ghasemi 29-May-14 2:17am    
Thankyou Ward
I Solve that
Ward 29-May-14 3:16am    
How did you solve the double click? I think you will have to register your application as default program for opening txt files in windows. Again the first argument in args will contain the the full filename and you will be able to use the exact same application.
alireza ghasemi 29-May-14 3:24am    
it was so easy. I right clicked on the file and choice open with then selected the EXE file.
it is working right now.
but I change the fi.name to fi.FullName.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900