2011-09-06 31 views
3

我想传递参数,以便通过使用Environment.GetCommandLineArgs读它在我的VSTO插件到WINWORD()。字的命令行参数空间问题

如果一个参数值包含空格,我无法逃脱字符串。

这是工作:

winword.exe /myVar1:C:\folder\whatever1.doc /myVar2:C:\folder\somethingelese.txt C:\example.doc 

这不是工作:

winword.exe /myVar1:"C:\folder with space\whatever1.doc" /myVar2:"C:\folder with space 2\somethingelese.txt" C:\example.doc 
+0

如果你还没有完全放弃这个,我注意到,第二个例子中打开一个Word 2007的模板时,对我的作品。你使用的是不同版本的Word吗? – Chris

回答

2

尝试用下面的命令:

winword.exe "/myVar1:C:\folder with space\whatever1.doc" "/myVar2:C:\folder with space 2\somethingelese.txt" C:\example.doc 

如果还是不行,请给我们由GetCommandLineArgs返回的数组的内容。

+0

不工作:(第二个参数没有设置?! – wuhi

+0

GetCommandLineArgs返回的数组是什么?错误可能出现在您的代码中(也许您没有正确读取数值) – Guillaume

+0

这里是内容 - \t \t args \t {串[2]} \t串[] \t \t [0] \t “WINWORD.EXE” \t串 \t \t [1] \t “/ myVar1:C:\\与空间\\ whatever1.doc文件夹” \t串 – wuhi