Small C# issue.

Associate
Joined
14 Jan 2010
Posts
1,192
Location
Northern Ireland
I'm programming an application which also happens to start Crysis 2, however a small problem with starting the application is that I need to use "\b" which create some sort of special character.

Code:
            Process crysis2 = new Process();
            crysis2.StartInfo.FileName = "Crysis2";
            crysis2.StartInfo.WorkingDirectory = @path+"\bin32";
            crysis2.Start();

Where path = D:\Steam\steamapps\common\crysis2

I know that isn't where the problem is, it's with that \b thing, and I can't seem to figure out away around it.
 
Just use a double backslash to escape the special character or use another @ symbol.

eg
crysis2.StartInfo.WorkingDirectory = @path+"\\bin32";
or
crysis2.StartInfo.WorkingDirectory = @path + @"\bin32";

That should do the trick :)
 
Just use a double backslash to escape the special character or use another @ symbol.

eg
crysis2.StartInfo.WorkingDirectory = @path+"\\bin32";
or
crysis2.StartInfo.WorkingDirectory = @path + @"\bin32";

That should do the trick :)

I didn't even think of that :o

Thanks. :)
 
You really shouldn't use methods like that to combine paths.
.NET comes with various classes to help with file and path manipulation.

Code:
crysis2.StartInfo.WorkingDirectory = System.IO.Path.Combine(path, "bin32");

Should do what you want.
 
Use C# Object Initializers for full "it makes R#'er go green" XP points.

Code:
using System.IO;

...

var proc = new Process {
   StartInfo.FileName = "Crysis2",
   StartInfo.WorkingDirectory = Path.Combine(path, "bin32")
};

proc.Start();
 
Last edited:
Use C# Object Initializers for full "it makes R#'er go green" XP points.

Code:
using System.IO;

...

var proc = new Process {
   StartInfo.FileName = "Crysis2",
   StartInfo.WorkingDirectory = Path.Combine(path, "bin32")
};

proc.Start();
That won't compile (at least on 3.5 :p) need to use:
Code:
using System.IO;

...

var proc = new Process {
   StartInfo = new ProcessStartInfo {
      FileName = "Crysis2",
      WorkingDirectory = Path.Combine(path, "bin32")
   }
};

proc.Start();
 
Back
Top Bottom