Share via


_XDocumentEventSink2_Event.OnSaveRequest 事件

在从 Microsoft InfoPath 用户界面或者使用 SaveSaveAs 方法来调用保存操作时发生。

命名空间:  Microsoft.Office.Interop.InfoPath.SemiTrust
程序集:  Microsoft.Office.Interop.InfoPath.SemiTrust(位于 Microsoft.Office.Interop.InfoPath.SemiTrust.dll 中)

语法

声明
Event OnSaveRequest As _XDocumentEventSink2_OnSaveRequestEventHandler
用法
Dim instance As _XDocumentEventSink2_Event
Dim handler As _XDocumentEventSink2_OnSaveRequestEventHandler

AddHandler instance.OnSaveRequest, handler
event _XDocumentEventSink2_OnSaveRequestEventHandler OnSaveRequest

备注

如果 SaveEventObject 对象的 ReturnStatus 属性设置为 false,InfoPath 将取消保存操作。如果错误发生在 OnSaveRequest 事件的代码中,InfoPath 将忽略该错误并依赖于 SaveEventObject 对象的 ReturnStatus 属性。如果没有显式设置 ReturnStatus 属性,则使用默认值 false。

在关闭 InfoPath 表单时,ReturnStatus 属性将与 IsCancelled 属性协同运行。如果文档中有尚未保存的更改,并且用户取消了保存操作,则可将 IsCancelled 属性设置为 true 以便关闭 InfoPath。

示例

[InfoPathEventHandler(EventType=InfoPathEventType.OnSaveRequest)]
public void OnSaveRequest(SaveEvent e)
 {
  if(thisXDocument.DOM.selectSingleNode("//my:field2").text == "")
   thisXDocument.UI.Alert("Field2 is empty.\nYou cannot save the form.");
  else
e.IsCancelled = e.PerformSaveOperation();
// set ReturnStatus to false if you want InfoPath
// to show an additional error message
e.ReturnStatus = true;
}

另请参阅

引用

_XDocumentEventSink2_Event 接口

_XDocumentEventSink2_Event 成员

Microsoft.Office.Interop.InfoPath.SemiTrust 命名空间