Word Automation 中的 SaveAs 给我一个“这不是有效的文件名”错误

发布于 2024-11-08 13:30:14 字数 875 浏览 0 评论 0原文

我正在尝试使用 Word Automation 将文档保存到网络驱动器。我可以完全访问它。我什至可以通过驱动器上的代码创建目录...

我使用 Directory.CreateDirectory 在驱动器上创建了一个目录,没有任何问题...问题是尝试使用 Word Automation 将 Word 文档保存到创建的目录目录。

文件名和路径采用以下格式: \\gy2k3001\Folder1\Folder2\Test.docx

我使用的代码是这样的:

    Object documentPath=filepath;
    wd.ActiveDocument.SaveAs(ref documentPath, ref _oMissing, ref _oMissing, ref _oMissing, ref _oMissing, ref _oMissing, ref _oMissing, ref _oMissing, ref _oMissing, ref _oMissing, ref _oMissing, ref _oMissing, ref _oMissing, ref _oMissing, ref _oMissing, ref _oMissing);

其中 filepath 等于 @"\\gy2k3001\Folder1 \Folder2\Test.docx"

我收到的错误是这样的:"这不是有效的文件名。\n 尝试以下一项或多项操作:\n* 检查路径以确保输入正确。\n* 从文件和文件夹列表中选择一个文件。"

我在这里做错了什么?您无法在自动化中使用网络驱动器进行保存吗?

我可以将其保存在本地硬盘上......就像我之前所说的那样,我拥有该网络目录所需的所有权限

I am trying to using Word Automation to save a document to a network drive. I have full access to it. I can even create directories through code on the drive.....

I created a directory on the drive using Directory.CreateDirectory with no problem..... The issue is trying to use Word Automation to save a word document to that created directory.

the file name and path is in this format: \\gy2k3001\Folder1\Folder2\Test.docx

The code I use is this:

    Object documentPath=filepath;
    wd.ActiveDocument.SaveAs(ref documentPath, ref _oMissing, ref _oMissing, ref _oMissing, ref _oMissing, ref _oMissing, ref _oMissing, ref _oMissing, ref _oMissing, ref _oMissing, ref _oMissing, ref _oMissing, ref _oMissing, ref _oMissing, ref _oMissing, ref _oMissing);

where filepath is equal to @"\\gy2k3001\Folder1\Folder2\Test.docx"

The error I get is this: "This is not a valid file name.\n Try one or more of the following:\n* Check the path to make sure it was typed correctly.\n* Select a file from the list of files and folders."

What am I doing wrong here? Are you not able to save using network drives in automation?

I can save it fine on my local hard drive..... and like I said before I have all the permissions I need to that network directory

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雨后彩虹 2024-11-15 13:30:14

嗯...问题似乎是服务器和 wd.ActiveDocument.SaveAs 相处得不太好...所以我最终将文档保存在其他地方并以编程方式将文件复制到它需要的目的地go to,而不是直接保存到目的地

Well.... The problem seemed to be that the server and the wd.ActiveDocument.SaveAs didn't get along too well... so I ended up saving the document elsewhere and programmatically copying the file to the destination that it needed to go to, instead of SAVING it to the destination directly

2024-11-15 13:30:14

运行程序的用户是否对该目录具有“创建文件”权限?这听起来就是问题所在。

仅仅能够创建目录可能还不够。

另外,该程序是以什么用户身份运行的? (我认为它是一个在您本地权限下运行的 EXE,但只是检查一下)

Does the user that the program is running under have "create file" permissions on that directory? That's what it sounds like the problem is.

Just being able to create the directory may not be sufficient.

Also, what user is that program being run as? (I presume it's an EXE running under your local rights, but just checking)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文