繁体   English   中英

操作字符串以打开Word文档

[英]manipulate a string for opening word document

基于C#中的Open Word文档,该文档的path中有空格 我想问一下如何做,但是要从列表框中获取路径。 我知道如果我使用@"path" ,它将起作用,但是打开时如何对listBox.SelectedItem.ToString()进行相同listBox.SelectedItem.ToString()

var _p = new Process();
_p.StartInfo.FileName = "Word.exe"
_p.StartInfo.Arguments = lbFiles.SelectedItem.ToString();

假设我要打开“ C:\\ new word document.docx”。 Word给出了一个错误,找不到路径“ C:\\ new.doc”的任何想法。

尝试将文件名也用引号引起来:

_p.StartInfo.Arguments = string.Format("\"{0}\"", lbFiles.SelectedItem);

另外, Word.exe在我的系统上不起作用。 您可能需要将其更改为:

_p.StartInfo.FileName = "WinWord.exe"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM