Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Infopath form with Submit via email and SP Library

Status
Not open for further replies.

woter324

Technical User
Jan 26, 2007
179
GB
Hi,

I have created a form in InfoPath 2007 and published it to MOSS2007 with the ability to complete as a web page.

I have followed these instructions to the letter, but after going through the rigmarol of activating the form because it now has code in it, I get the following error when I click the submit button.

Code:
InfoPath cannot submit the form.
The OnSubmitRequest event handler did not work.

Request failed.
   at Microsoft.Office.InfoPath.MsxmlNavigator.IsValidNode(MsxmlNode test)
   at Microsoft.Office.InfoPath.MsxmlNavigator.MoveToFirstChild()
   at MS.Internal.Xml.XPath.XPathDescendantIterator.MoveNext()
   at MS.Internal.Xml.XPath.DescendantQuery.Advance()
   at MS.Internal.Xml.XPath.XPathSelectionIterator.MoveNext()
   at System.Xml.XPath.XPathNavigator.SelectSingleNode(XPathExpression expression)
   at System.Xml.XPath.XPathNavigator.SelectSingleNode(String xpath, IXmlNamespaceResolver resolver)
   at NewStartersFormV1.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)
I only get this error if I run the form from IE on my PC with InfoPath installed (where it uses InfoPath) whereas running from Firefox on my PC or another machine without InfoPath, I get:

Code:
An entry has been added to the Windows event log of the server. [b]Log ID:[/b]5337

An error occurred while the form was being submitted.
The submit event handler returned a value indicating that the submit failed.

The full C# code attached to the Submit button looks like this:
Code:
using Microsoft.Office.InfoPath;
using System;
using System.Xml;
using System.Xml.XPath;

namespace NewStartersFormV1
{
    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 Library Submit"];
            spConn.Execute();

            // Set the properties for the email
            string toAddress = root.SelectSingleNode(
            "//my:sendTo", NamespaceManager).Value;
            EmailSubmitConnection emailConn =
            (EmailSubmitConnection)DataConnections["Email Submit"];
            emailConn.To.SetStringValue(toAddress);
            emailConn.Subject.SetStringValue("This subject was set from code");
            emailConn.Introduction = "This email was generated by code.";
            emailConn.EmailAttachmentType = EmailAttachmentType.None;

            // Send the email
            emailConn.Execute();

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

If anyone can see what's wrong and give me a clue, I'd be most grateful.

My two data sources are correctly labeled as per the code.

Many thanks.

W
 
P.S.

I've made sure all the links to the pages are at the same level (Site Collection root?). i.e. and I have given myself 'Full Control' everywhere I can find.

Not that I understand what the error message is saying. No 'File not found' or 'Access Denied' messages anywhere.

Thanks again.

A stressed W. lol
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top