SaveAs in Word Automation gives me a "This is not a valid file name" error
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
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
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)
精彩评论