-3

Folks, I have a simple expression that I am able to run by pasting it in the "search program and files" :

"C:\Program Files (x86)\notepad.exe" /BF: "D:\BatchMerge\DcaBatch.bpf"

If I have use the same expression in the C# code, what should I use? I searched on stackflow and found "Process.startinfo". I tried using it as below:

Process.Start(""C:\Program Files (x86)\notepad.exe" /BF: "D:\BatchMerge\DcaBatch.bpf"");

That does not work!

user7157732
  • 347
  • 1
  • 8
  • 24
  • 1
    escape your double quote and it will work – Steve Nov 13 '17 at 19:48
  • I did. It says "unrecognizable escape sequence" wherever I have "\" in the expression. – user7157732 Nov 13 '17 at 19:50
  • because you also need to escape your \ in c:\ – Steve Nov 13 '17 at 19:54
  • How to escape strings properly is a very basic task that all developers need to know. You need to go learn how this works in .NET strings. –  Nov 13 '17 at 19:56
  • @Will : I am new to C#. Agree on the learning part but I don't buy the concept of giving "-" . Not everyone on the forum knows everything. Anyway thnx. – user7157732 Nov 13 '17 at 20:00
  • SO isn't a forum, and it's not the right place to learn how to program. You'd do yourself a good service to buy a good C# book like CLR Via C# and read it. Shouldn't take more than a day and you can avoid getting dinged for asking very basic questions. You can learn more about how SO works by visiting [meta]. Good luck! –  Nov 13 '17 at 20:03

1 Answers1

2

You should separate the executable from the arguments. Look at this overload. So you'd do this instead:

Process.Start(@"C:\Program Files (x86)\notepad.exe", "/BF: \"D:\\BatchMerge\\DcaBatch.bpf\"");
itsme86
  • 19,266
  • 4
  • 41
  • 57