Createworddocument问题,找不到文件 [英] Createworddocument issue, file not found

查看:156
本文介绍了Createworddocument问题,找不到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到错误消息,该文件不存在,下面是目前为止的代码。



这假设创建一个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

推荐答案

C :\Desktop \ 不是桌面文件夹的路径, C:\Temp \ 不是temp的路径夹。真实路径位于您的用户个人资料文件夹中。



您可以通过以下方式获取临时文件夹的路径:

C:\Desktop\ is not the path to the desktop folder, and C:\Temp\ is not the path to the temp folder. The real paths are within your user profile folder.

You can get the path to the temp folder with:
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问题,找不到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆