Problem with spaces in a filepath - commandline execution in C#

北城以北 提交于 2019-12-01 21:02:47
proc.StartInfo.Arguments = text + " " + txtBoxUrls.Text + " " + txtFileName.Text; 

In this line, text already contains the properly quoted version of your txtBoxUrls strings. Why do you add them again in unquoted form (+ txtBoxUrls.Text)? If I understood your code corrently, the following should work:

proc.StartInfo.Arguments = text + " " + txtFileName.Text;    

In fact, since txtFileName.Text could probably contain spaces, you should quote it as well, just to be sure:

proc.StartInfo.Arguments = text + " \"" + txtFileName.Text + "\"";    

(or, using your syntax:)

proc.StartInfo.Arguments = text + @" """ + txtFileName.Text + @"""";    

Usually to get around spaces in filenames, you'll need to wrap your argument in double quotes. If you leave out the quotes the program will think it has two arguments. Something like this...

wk.exe "C:\VS2008\Projects\web2pdf\web2pdf\bin\Release\Test Page.htm"

Also, this line appears to have too many quotes. Four, instead of three:

s1 = @"""" + s + @"""";

Take a look at the Path class - http://msdn.microsoft.com/en-us/library/system.io.path.aspx

Path.combine might be what you are looking for.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!