Avatar of Andy Brown
Andy Brown
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Extracting a hyperlink from the command line

I'm new to c# and need a bit of guidance on something that I fear is very obvious (but haven't figured out).  I want to pass a hyperlink via the command line to a variable called strHyperlink.  I was thinking of something like this for the command line:

D:\Testbed\Sandbox.exe http://website.com

I have added the variable to the Form class
string strHyperlink = Environment.CommandLine;

Open in new window


However, when I try to view the switch using the following:

var result = MessageBox.Show(strHyperlink, "Test", MessageBoxButtons.OK, MessageBoxIcon.Information);

Open in new window


I get:

"D:\Testbed\Sandbox.exe http://website.com"

Can someone please let me know how to get the hyperlink (in the cleanest possible way).  Thank you.
C#

Avatar of undefined
Last Comment
Andy Brown

8/22/2022 - Mon
AndyAinscow

Dim arguments As String() = Environment.GetCommandLineArgs()
arguments(1) contains the hyperlink
ASKER CERTIFIED SOLUTION
Pawan Kumar

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Andy Brown

ASKER
Great stuff - thank you.
AndyAinscow

duh, I gave you the vb version for some reason.
Note you also need to check that there are more than 1 arguments (the first one is the application iteself)
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Pawan Kumar

welcome happy to help.
Andy Brown

ASKER
Thank you both.