ChangeFileOpenDirectory不会更改Word“另存为”对话框中的路径 [英] ChangeFileOpenDirectory not changing path in Word 'SaveAs' dialog
问题描述
我们为Word 2010(32位Office)开发了一个VSTO Word AddIn。
We have developed a VSTO Word AddIn for Word 2010 (32-bit Office).
在这个加载项中,我们正在拦截'Before SaveAs事件',也就是说,在Word显示"另存为"对话框之前。
Within this add-in, we are intercepting a 'Before SaveAs event', that is, before Word displays the 'Save as' dialog.
我们正在使用Application.ChangeFileOpenDirectory方法(Word)来改变"另存为"对话框建议的路径。我们还试图设置Options.DefaultFilePath属性,但没有成功。
We are using the Application.ChangeFileOpenDirectory method (Word) to the alter the path that 'Save as' dialog will suggest. We have also tried to set the Options.DefaultFilePath property, without success.
在第一个测试场景中,当我们从"开始"菜单启动Word 2010,然后选择"另存为"时,该对话框将显示传递给ChangeFileOpenDirectory的路径 - 正如预期的那样!
In the first test scenario, when we start Word 2010 from the Start menu, and then select 'Save as', the dialog will show the path passed to ChangeFileOpenDirectory - as expected!
然而,当我们通过双击C:\ tmp中的文档来启动Word 2010时,例如,ChangeFileOpenDirectory似乎不起作用,对话框将错误地显示C:\ tmp而不是传递给ChangeFileOpenDirectory的路径
However, when we start Word 2010 through a double-click on a document from C:\tmp, for instance, ChangeFileOpenDirectory does not seem to work, the dialog will wrongly show C:\tmp instead of the path passed to ChangeFileOpenDirectory
我们需要可靠在"另存为"之前设置路径的方式,对话框
将显示。
We need a reliable way to set the path before the 'Save as', the dialog will show.
我们的测试系统:
Windows 7 Enterprise,SP1,Build 7601
Word 2010,14.0.7173.5000(32-Bit)
Our test system:
Windows 7 Enterprise, SP1, Build 7601
Word 2010, 14.0.7173.5000 (32-Bit)
推荐答案
你好Alpensturm,
Hi Alpensturm,
你是什么意思"在SaveAs活动之前"?你的意思是DocumentBeforeSave吗?
What do you mean by "Before SaveAs event"? Do you mean DocumentBeforeSave?
我建议你尝试下面的代码:
I suggest you try below code:
void Application_DocumentBeforeSave(Word.Document Doc, ref bool SaveAsUI, ref bool Cancel)
{
//disable built-in save as function
SaveAsUI = false;
Cancel = true;
Dialog d = Application.Dialogs[WdWordDialog.wdDialogFileSaveAs];
object oDlg = (object)d;
object[] oArgs = new object[1];
oArgs[0] = (object)@"D:\work\xx";
oDlg.GetType().InvokeMember("Name", BindingFlags.SetProperty, null, oDlg, oArgs);
d.Show(ref missing);
}
您可以参考以下链接获取更多信息。
You could refer the link below for more information.
#ChangeFileOpenDirectory不改变Word"另存为"对话框中的路径
https://social.msdn.microsoft.com/Forums/office/en-US/1b0e9dd6-599e-41be-a8a6-2a2d0df778e6 / set-document-path-in-word-saveas-dialog?forum = vsto
# ChangeFileOpenDirectory not changing path in Word 'SaveAs' dialog
https://social.msdn.microsoft.com/Forums/office/en-US/1b0e9dd6-599e-41be-a8a6-2a2d0df778e6/set-document-path-in-word-saveas-dialog?forum=vsto
最好的问候,
Best Regards,
Edward
这篇关于ChangeFileOpenDirectory不会更改Word“另存为”对话框中的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!