_XDocumentEventSink2_Event.OnSaveRequest Event

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

Namespace:  Microsoft.Office.Interop.InfoPath.SemiTrust
Assembly:  Microsoft.Office.Interop.InfoPath.SemiTrust (in Microsoft.Office.Interop.InfoPath.SemiTrust.dll)

Syntax

'Declaration
Event OnSaveRequest As _XDocumentEventSink2_OnSaveRequestEventHandler
'Usage
Dim instance As _XDocumentEventSink2_Event
Dim handler As _XDocumentEventSink2_OnSaveRequestEventHandler

AddHandler instance.OnSaveRequest, handler
event _XDocumentEventSink2_OnSaveRequestEventHandler OnSaveRequest

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.

Examples

[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;
}

See Also

Reference

_XDocumentEventSink2_Event Interface

_XDocumentEventSink2_Event Members

Microsoft.Office.Interop.InfoPath.SemiTrust Namespace