5

I want to add my Application so when I right click on a file , it shows the Send To > My App.

If its possible then , when I click on the SendTo button , how can I get the Selected file ...?? I didn't tried anything before or even found something that can help. Thanks :=)

Gurupad Hegde
  • 2,155
  • 15
  • 30
  • You are really being vague here. You want to add your application to what? Click on a file where? You really need to give some context. – StijnvanGaal Nov 24 '15 at 14:35
  • I think he means right-clicking on a file in the Windows Explorer window or Total Commander, and adding his program as an option to the 'Send To' item. – Marleen Schilt Nov 24 '15 at 14:39

1 Answers1

12

You can add a shortcut to your application to

%AppData%\Microsoft\Windows\SendTo

To navigate to that folder, you can also open a explorer window and type

shell:sendto

into the addressbar.

When you use the Send To context menu, a new instance of your application will be started and you can get the path to the file which you sent to your application via the commandline arguments. For a console application this would be the args parameter of the Main method. Another way is Environment.GetCommandLineArgs();.


Edit: Add sample console application

namespace TestApplication
{
    public class Program
    {
        public void Main(string[] args)
        {
            String filePath = args[0];
            Console.Write("The file you sent here: ");
            Console.WriteLine(filePath);
            Console.ReadLine();
        }
    }
}

This assumes that the app ist started with no other arguments. If there are other arguments, the filepath could be on another index in the args array.

Sample output of this console app could be:

The file you sent here: C:\tmp\file.txt
Philipp Grathwohl
  • 2,726
  • 3
  • 27
  • 38
  • i didn't understand how can i get the File i selected ? can You Show me an example Please? – Somebody You don't know Nov 24 '15 at 19:22
  • I edited the answer and added a sample console application source. – Philipp Grathwohl Nov 24 '15 at 20:36
  • thank you , but the problem is that when i add shortcut to my app on the SendTo Folder , it doesnt show on the list when i rightclick ? – Somebody You don't know Nov 25 '15 at 16:37
  • Did you add the shortcut for the correct user. The SendTo directory is user specific. – Philipp Grathwohl Nov 26 '15 at 08:32
  • I tried it on a Windows 7 machine, what version are you working on? – Philipp Grathwohl Nov 26 '15 at 20:30
  • I had another try on Windows 10 and realized I mentioned the "Roaming" folder separately in my answer but it's already included in the %AppData% environment variable. I edited my answer accordingly. Maybe this is the reason it's not working? To be sure you should try it with `shell:sendto`. – Philipp Grathwohl Nov 27 '15 at 07:20
  • Cool , now its working thank you. can i know how to get the filename in a C# GUI ? not console.. :) thank you. – Somebody You don't know Nov 27 '15 at 10:31
  • You can use Environment.GetCommandLineArgs(). Be careful, the GetCommandLineArgs also returns an String array, but the first item is the executable file name. See: https://msdn.microsoft.com/en-us/library/system.environment.getcommandlineargs(v=vs.110).aspx and http://stackoverflow.com/questions/1179532/how-do-i-pass-command-line-arguments-to-a-winforms-application – Philipp Grathwohl Nov 27 '15 at 10:41