Monday, November 24, 2008

Dynamically Updating Data Connections:

Wondering how to change Data connections dynamically in InfoPath Forms so that you can deploy the solution seamlessly from DEV-QA-Staging-Production.

Here is Sample Code for MainSubmit()

private void MainSubmit(SubmitEventArgs e)
{
bool bSuccessful = false;
try
{
FileSubmitConnection fc = (FileSubmitConnection)this.DataConnections["MainSubmit"];
Uri url = new Uri(ConfigurationManager.AppSettings["Submit"].ToString());
fc.FolderUrl = url.AbsoluteUri;
fc.Execute();
bSuccessful = true;
}
catch
{
System.Diagnostics.EventLog.WriteEntry("MainSubmit", "MainSubmit: Failed to Submit();");
}
// If the submit operation is successful, set
// e.CancelableArgs.Cancel = false;
e.CancelableArgs.Cancel = !bSuccessful;
}

Note:
a. Add the using System.Configuration Name Space to your solution so that you can read the webconfig.
b. Add fallowing key under in web.config file:
<add key="Submit" value="http://<url>/<LibraryName>/" />

No comments: