Dynamic String x Static String
Im creating a Windows Service and I want to put a dynamic path in the code. But it only accepts static code.
This works:
Process.Start("C:\\Program Files\\Program\\Program.exe", "-socket 12345");
But this doesnt:
String path = "C:\\Program Files\\Program";
String programName = "\\Program.exe";
String fileLocation = path 开发者_运维问答+ programName;
Process.Start(fileLocation, "-socket 12345");
Someone can help me?
You should never concat paths. Use Path.Combine
instead.
String path = @"C:\Program Files\Program";
String programName = "Program.exe";
String fileLocation = System.IO.Path.Combine(path, programName);
Process.Start(fileLocation, "-socket 12345");
Your code examples result in identical calls to Process.Start
. Whatever the problem is, it's not shown here.
精彩评论