【问题标题】:manipulate a string for opening word document操作打开word文档的字符串
【发布时间】:2015-03-06 09:29:45
【问题描述】:

基于Opening Word document within C# that has spaces in the path。我想问一下如何做同样的事情,但是当从列表框中获取路径时。我知道如果我使用@"path" 它会起作用,但是我如何在打开时对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”任何想法如何做到这一点。

【问题讨论】:

  • "Word.exe" 仅用于演示文稿,估价器是根据此post从注册表中获取的

标签: c# ms-word


【解决方案1】:

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

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

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

_p.StartInfo.FileName = "WinWord.exe"

【讨论】:

  • System.dll 中出现“System.InvalidOperationException”类型的未处理异常附加信息:无法启动进程,因为未提供文件名。
  • "\"C:\\Users\\User\\Desktop\\New Microsoft Word Document.docx\""
  • 这是我得到的结果(用你的解决方案)
  • 我从注册表中获取 _p.StartInfo.FileName - 基于此 post
  • 所以WinWord.exe 不相关,但路径字符串应该是某种操作方式
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多