I want to implement a wpf application that will listen
to an event that comes from the desktop from the Send To
shortcut. Such as
right click on the file and select send to app
, then get the file path.
How would that be developed?
SendTo resolves the link in the %APPDATA%\Microsoft\Windows\SendTo folder and passes the filename as a parameter to the proper executable. You need to make your program accept command parameters and then process them.
EDIT: I originally missed the mention of WPF. So you could process command line args like this.
In you App.xaml add an entry for Startup like this:
<Application x:Class="WpfApplication4.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="App_OnStartup"
StartupUri="MainWindow.xaml">
<Application.Resources />
</Application>
In your App.xaml.cs add the App_OnStartup like this and store the args into an accessible variable:
namespace WpfApplication4
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
public static string[] mArgs;
private void App_OnStartup(object sender, StartupEventArgs e)
{
if (e.Args.Length > 0)
{
mArgs = e.Args;
}
}
}
}
In your main window get the args and do something with it:
namespace WpfApplication4
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
string[] args = App.mArgs;
//do your procedure with the args!
}
}
}
Then place a shortcut to your program in the %APPDATA%\Microsoft\Windows\SendTo folder. When you right click on a file and SendTo your app, the filename will be the args that are passed into your app.