问题描述
我收到错误消息,该文件不存在,下面是目前为止的代码。
这假设创建一个word文档并替换它,我认为问题是我没有访问C:/ temp文件夹,但我不知道用什么替换它?试过C:/桌面仍然无法正常工作。
谢谢
I get an error message that the word file does not exist, below is the code so far.
this supposes to create a word document and replaces words in it, I think the problem is that I do not have access to the C:/temp folder, but i do not know what to replace it with? Tried C:/desktop still didnt work.
thanks
推荐答案
System.IO.Path.GetTempPath()
您可以通过以下方式获取桌面文件夹的路径:
You can get the path to the desktop folder with:
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
因此,要将文件保存在桌面上,您可以使用:
So, to save the file on your desktop, you would use:
string destinationFilePath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
"new.doc");
在任何一种情况下, CreateWordDocument
函数的第一个参数都需要是现有的真实路径要打开的文件。如果指定了不存在的路径,则会收到(拼写错误的)错误消息。
In either case, the first parameter to your CreateWordDocument
function needs to be the real path of the existing file you want to open. If you specify a path that doesn't exist, you'll get your (misspelled) error message.
这篇关于Createworddocument问题,找不到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!