Open Program with dragging file(PDF) and even recover the path

Asked

Viewed 80 times

1

Hello, I am with a little complicated need, I am developing an application that sends pdf files to an application via webservices. I just want to let this problem begin in a few different ways. I will try to explain by example. When I have a file in Work and drag it to a shortcut the word the same is opened, and this happens with several programs. Or when you right-click on a word file and in the context menu "send to " windows word appears and it opens the file. I would like my application to work in this way. I’m working C# Windows Forms in Visual Studio. I was able to get a similar function by dragging the file to the textbox with the Dragdrop Event. I’ve done a lot of Google, but I don’t know if I’m looking the wrong way, because I can’t find anything. If anyone has ever done anything like this or has any idea how to do it.

1 answer

1


Just handle the arguments started next to the application. With this you can even call the application from the command line, like this:

enviarpdf.exe "c:\pdf\arquivo.pdf"

to treat the arguments, simply declare a string array as a method parameter main:

    static void Main(string[] args)
    {

        if (args.Length != 0)
        {
            string arg = args[0];
            MessageBox.Show(arg);
        }

     }

How your application is winforms and whereas you need the path within Form1, it could be done so:

    static void Main(string[] args)
    {

        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1(args.Lenght >0 ? args[0] : null));

     }

Thus, the first argument will be passed to Form1.

ps. Of course, in Form1, you must put the constructor to receive a string type parameter.

public Form1(string _arquivo)
{
   InitializeComponent();
   ArquivoPdf = _arquivo;
}
  • I will try to implement

  • It worked.. Thanks man, now I just need to figure out how to create a shortcut from the "send to" menu of windows getting the file, but it was worth even

  • blz, I never did this to "send to" but it will certainly be in windows records. hugs

Browser other questions tagged

You are not signed in. Login or sign up in order to post.