Edit

Share via


_XDocumentEventSink2_Event.OnSaveRequest Event

Definition

Occurs when the save operation is invoked from the Microsoft InfoPath user interface or by using the Save() or SaveAs(String) methods.

public:
 event Microsoft::Office::Interop::InfoPath::SemiTrust::_XDocumentEventSink2_OnSaveRequestEventHandler ^ OnSaveRequest;
event Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_OnSaveRequestEventHandler OnSaveRequest;
member this.OnSaveRequest : Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_OnSaveRequestEventHandler 
Event OnSaveRequest As _XDocumentEventSink2_OnSaveRequestEventHandler 

Event Type

Examples

[InfoPathEventHandler(EventType=InfoPathEventType.<span class="label">OnSaveRequest</span>)]
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;
}
[InfoPathEventHandler(EventType=InfoPathEventType.<span class="label">OnSaveRequest</span>)]
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;
}

Remarks

If the ReturnStatus property of the SaveEventObject object is set to false, InfoPath cancels the save operation. If an error occurs in the code for the OnSaveRequest event, InfoPath ignores the error and relies on the ReturnStatus property of the SaveEventObject object If the ReturnStatus property is not explicitly set, the default value of false is used.

The ReturnStatus property works in conjunction with the IsCancelled property when the InfoPath form is closing. If the document has changes that have not been saved and the user cancels the save operation, the IsCancelled property can be set to true to allow InfoPath to close.

Applies to