Just some extra info:
When you associate a file type with your application (which you either do manually, or as part of the install for your application) - when the file is double-clicked, your application is opened and the path to the file is supplied as the first command-line argument.
This is available in the args parameter of the
Program.Main(string[] args)
method, it is also available anywhere in your app in
Environment.GetCommandLineArgs()
, (although, beware the first element will be your app's exe)
For an application deployed through ClickOnce, you need to access:
AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData
For a WPF app, you need to handle the startup event in App.xaml:
<application x:class="XmlViewer.App" xmlns:x="#unknown">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:XmlViewer"
Startup="Application_Startup">
<application.resources>
</application.resources>
</application>
public partial class App : Application
{
private void Application_Startup(object sender, StartupEventArgs e)
{
if (System.IO.File.Exists(e.Args[0]))
{
}
}
}