user496949
user496949

Reputation: 86185

how to make sure the file name is quoted when it has space

When use Process.startInfo.Arguments, I have filename as one of the argument,

StartInfo.Arguments = filename

I am wondering how to make sure it is correct in the case that filename is "test test".

Upvotes: 1

Views: 146

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1064114

I would simply always quote it; since "test" is valid too.

I don't know if there is inbuilt file escaping anywhere, but

procStart.Arguments = "blah blip -in \"" + filePath + "\" more args";

should do...

If you wanted you could get fancy with checking the input string (filePath above), but it probably isn't worth checking the edge-cases. For the same reason that if I'm writing TSQL over an unknown table, I'd always add explicit [ / ] (without bothering to check if it needs it).

Upvotes: 8

Related Questions