Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Environment.GetCommandLineArgs in a Windows 8 Store App

I created a brand new, vanilla c# Windows 8 Store app. In the App() function, I put a line of code to gather the Command line arguments. The IDE complains that GetCommandLineArgs() is not part of Environment.

public App()
{
    this.InitializeComponent();
    this.Suspending += OnSuspending;

    String[] arguments = Environment.GetCommandLineArgs();
}

This page on Microsoft's site seems to indicate that this is supported in .NET 4.5. What gives?

(I could technically gather the args as an App() parameter, but I'd prefer not to. Other lines of code also call this, and I'd prefer to leave them "as is". Moreover, I'm just curious why this isn't working, seems like it should.

like image 709
Todd Davis Avatar asked Mar 17 '26 03:03

Todd Davis


1 Answers

How would you pass in an argument to a Windows Store app on the command line? The closest analog would probably be LaunchActivatedEventArgs which comes into play, for instance, if you have secondary tiles (say a tile for the weather in Boston and one in Honolulu - same app, different arguments).

Check out How activate an app for additional details.

UPDATED in response to Todd's first comment.

What you're looking for then is File Activation. You can indicate your file knows how to process, say .txt files. When user right clicks on a .txt file in File Explorer, your app will appear as an "Open With.." option. When the user picks your app as the one he/she wants to use to process the file, your app will launch (or just activate if already running) and its OnFileActivated event will fire, through which you can get to the file(s) that were selected.

like image 152
Jim O'Neil Avatar answered Mar 18 '26 17:03

Jim O'Neil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!