Infosys Microsoft Alliance and Solutions blog

« More on Windows 7 | Main | Command prompt instance counting »

WPF: Working with command line arguments

The other day I hit upon this blog that describes how to work with command line arguments and custom file extensions in WPF applications. We have been using this in our application for a while now. I am however surprised to note that double clicking a file required Avi to work with different syntax.

I am simplifying the logic we have in our application to showcase here and it is pretty much same as what Avi has shown.

        public static string commandArgs = string.Empty;


        protected override void OnStartup(StartupEventArgs e)


            if (e.Args!= null && e.Args.Length > 0)


                commandArgs = e.Args[0];



We have some custom file extension that we have associated with our application. And on double clicking such a file, our application launches and we still very much get the file name as part of command line arguments, without having to worry about accesssing it from AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[0].

And we have been working with .net 3.5 and our code works both without SP1 and with SP1

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

Please key in the two words you see in the box to validate your identity as an authentic user and reduce spam.

Subscribe to this blog's feed

Follow us on

Blogger Profiles

Infosys on Twitter