I have a WPF C# application, to which I have to pass command line argument. The argument is actually a URL, which I have to then use in my application?
How are these command line arguments passed in WPF C#, so that the application can pickup the url during launch?
What are Command Line Arguments in C? Command line arguments are the arguments which the user gives from the operating system's command line during the time of execution. Earlier, we used main() functions without arguments. These command line arguments are handled by the main() function.
A command-line argument is nothing but the information that we pass after typing the name of the Java program during the program execution. These arguments get stored as Strings in a String array that is passed to the main() function. We can use these command-line arguments as input in our Java program.
Properties of Command Line Arguments: They are passed to main() function. They are parameters/arguments supplied to the program when it is invoked. They are used to control program from outside instead of hard coding those values inside the code. argv[argc] is a NULL pointer. argv[0] holds the name of the program.
In your App.xaml.cs
class App : Application
{
//Add this method override
protected override void OnStartup(StartupEventArgs e)
{
//e.Args is the string[] of command line arguments
}
}
It has been mentioned by linquize above, but I think it is worth an answer of its own, as it is so simple...
You can just use:
string[] args = Environment.GetCommandLineArgs();
That works anywhere in the application, not just in App.xaml.cs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With