R – Submit via code through a specific data connection InfoPath

infopathsharepoint

I've got an infopath form for which I am trying to convert the submit from rules to code, to add some functionality. All existing functionality needs to be kept. Currently it's in rules like:

if X submit through connection A
if Y submit through connection B
etc.

Connection A sends an email, connetion B sends a different email, connection C uploads to the sharepoint site.

I know how to submit through code, and have it submitting to the sharepoint site (the default connection), but how do I submit to a specific connection?

My current code is based on this MSDN which posts the XML to the site. I'm hoping to find a way to use the existing connections so I don't have to hand code all the email sends (there are several).

http://support.microsoft.com/kb/826993

Best Answer

Here is the code that allows you to get an instance of a specific data connection defined in the form:

FileSubmitConnection fc = DataConnections["dataConnectionsName"] 
                as FileSubmitConnection;

It seems like you should be able to retrieve any data connection by their name and be able to cast to the appropriate connection type, e.g. EmailSubmitConnection. All the connection types derive from the Microsoft.Office.InfoPath.DataConnection type: http://msdn.microsoft.com/en-us/library/microsoft.office.infopath.dataconnection(VS.80).aspx

You then call fc.Execute() to submit using that data connection.

More about submitting programmatically here, assuming we are talking InfoPath 2007: http://msdn.microsoft.com/en-us/library/cc704269.aspx

Related Topic