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.
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:
The full C# code attached to the Submit button looks like this:
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
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)
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