Do not remove characters from path name C#
I have a Windows Form Application that takes a command line argument as well. You can run the program by itself it has a GUI but when you run it in CLI it seems like C# removes some characters from my argument that I feed it.
This is how it works:
RemoveHTML.exe http://illen/configtc.aspx?IP=192.168.0.15&m=c
The app loads but crashes because C# removed the last part of the the URL! So what it's really seeing is
RemoveHTML.exe http://illen/configtc.aspx?IP=192.168.0.15
It remov开发者_运维技巧es the "&m=c" part and in my CLI I get this error:
C:\Users\admin\Documents\Visual Studio 2010\Projects\RemoveHTML\RemoveHTML\bin\Debug>RemoveHTML.exe http://illen/configtc.aspx?IP=192.168.0.15
'm' is not recognized as an internal or external command,operable program or batch file.
My code is located in the Form1_Load section and it is:
string MyURL;
string[] WebURL;
......
private void Form1_Load(object sender, EventArgs e)
{
string[] args = Environment.GetCommandLineArgs();
foreach (string arg in args)
{
WebURL[0] = args[1];
//WebURL[0] += "&m=c";
//WebURL[0] += (WebURL[0] + "&m=c");
//WebURL = args[1];
//MessageBox.Show(WebURL);
runtimeButton_Click(sender, e);
}
}
I am trying to find a way to not have C# remove the illegal characters, any ideas?
When calling your application, put the URL in quotes.
RemoveHTML.exe "http://illen/configtc.aspx?IP=192.168.0.15&m=c"
Its not a limitation of .NET or C#. Its the way the command parser works.
精彩评论