Custom Saving in InfoPath

A long time ago I wrote an article about extending save functionality in Microsoft Office InfoPath forms. The C# code samples in that article all showed types and members of the Microsoft.Office.Interop.InfoPath.SemiTrust namespace, which is compatible with the Office InfoPath 2003 object model.

Recently, I had to develop custom save functionality for an Office InfoPath 2007 form template. Like one of the samples in the article, the form template had to assume “control” of the Save As dialog box by providing a default location and file name. So, I basically re-wrote that sample with the Microsoft.Office.InfoPath namespace. The following shows what it looks like in the Office InfoPath 2007 solution.

public void FormEvents_Save(object sender, SaveEventArgs e)
    string userPrincipalName = MainDataSource.CreateNavigator().SelectSingleNode("//my:userPrincipalName", NamespaceManager).InnerXml;
    string projectName = MainDataSource.CreateNavigator().SelectSingleNode("//my:project", NamespaceManager).InnerXml;
    string startDate = MainDataSource.CreateNavigator().SelectSingleNode("//my:startDate", NamespaceManager).InnerXml;
    if (this.New || e.IsSaveAs == false)
        if (e.IsSaveAs)
            this.SetSaveAsDialogFilename(userPrincipalName + "_" + projectName + "_" + startDate);
        e.CancelableArgs.Cancel = false;
        e.CancelableArgs.Message = "This functionality has been disabled.";
        e.CancelableArgs.MessageDetails = "Only new forms can use the 'Save As' functionality.";

NOTE: Save using custom code is not supported in browser forms.

2 thoughts on “Custom Saving in InfoPath

  1. Hi, Richard.You need to create a Save event, which can be done by clicking “Edit” in the “Open and Save” category of the “Form Options” dialog box. Your code would then be inserted into the event handler stub.Regards,David

Leave a Reply

Your email address will not be published. Required fields are marked *