Closing InfoPath on form submit - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Closing InfoPath on form submit

Last post 03-24-2010 10:19 PM by Qazi Anis. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 03-23-2010 09:26 AM

    Closing InfoPath on form submit

    Hi

     I have designed a form with Intopath and it is working well, however I cannot close the form on Submit.   I have created some code as follows:

    {
        public partial class FormCode
        {
            // Member variables are not supported in browser-enabled forms.
            // Instead, write and read these values from the FormState
            // dictionary using code such as the following:
            //
            // private object _memberVariable
            // {
            //     get
            //     {
            //         return FormState["_memberVariable"];
            //     }
            //     set
            //     {
            //         FormState["_memberVariable"] = value;
            //     }
            // }

            // NOTE: The following procedure is required by Microsoft Office InfoPath.
            // It can be modified using Microsoft Office InfoPath.
            public void InternalStartup()
            {
                EventManager.FormEvents.Submit += new SubmitEventHandler(FormEvents_Submit);
            }

            public void FormEvents_Submit(object sender, SubmitEventArgs e)
            {
    // Get a reference to the main data source
    XPathNavigator root = MainDataSource.CreateNavigator();

    // Generate a name for the form to be saved in SharePoint
    string formName = Guid.NewGuid().ToString();

    // Set the name of the form on the data connection
    root.SelectSingleNode(
    "//my:formName", NamespaceManager).SetValue(formName);

    // Submit the form to SharePoint
    DataConnection spConn =
    DataConnections["SharePoint Submit"];
    spConn.Execute();

    // Indicate success
    e.CancelableArgs.Cancel = false;
            }
        }
    }

    I uploaded the form back to sharepoint and tested with the following result:

    Object reference not set to an instance of an object.
       at IT_Process_Form.FormCode.FormEvents_Submit(Object sender, SubmitEventArgs e)
       at Microsoft.Office.InfoPath.Internal.FormEventsHost.OnSubmit(DocReturnEvent pEvent)
       at Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_SinkHelper.OnSubmitRequest(DocReturnEvent pEvent)

    Any ideas?

  • 03-23-2010 10:20 PM In reply to

    Re: Closing InfoPath on form submit

    mark-scott:
    root.SelectSingleNode(
    "//my:formName", NamespaceManager).SetValue(formName);

     

    change it to

    root.SelectSingleNode("/my:myFields/my:formName",NamespaceManager).SetValue(formName);

     

    Qazi Anis
    System Analyst
    Bitwise Solutions
  • 03-24-2010 02:27 AM In reply to

    Thanks for the response. I've added the change but still get an error:

    System.NullReferenceException was unhandled by user code
      Message="Object reference not set to an instance of an object."
      Source="IT Process Form"
      StackTrace:
           at IT_Process_Form.FormCode.FormEvents_Submit(Object sender, SubmitEventArgs e)
           at Microsoft.Office.InfoPath.Internal.FormEventsHost.OnSubmit(DocReturnEvent pEvent)
           at Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_SinkHelper.OnSubmitRequest(DocReturnEvent pEvent)

    Please see the attached image for the C# code and error.


  • 03-24-2010 10:19 PM In reply to

    Re: Closing InfoPath on form submit

    it seems the path of the field is different, go to design mode in your form. In design tasks, click Datasources, go to your field and right click and select copy xpath, paste the same as an argument to root.SelectSinglenode(XPath, this.NamespaceManager).SetValue(formName)

    Qazi Anis
    System Analyst
    Bitwise Solutions
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.