Infopath Code
Here are some important codes for InfoPath.
Get Parameters in InfoPath Form:
if (e.InputParameters.ContainsKey("SaveLocation")) // Search for Query string (parameter) if found then set this parameter to a field.
SetFormFieldValue ("/my:ChangeOrder/my:SectionHide/my:ListURL", e.InputParameters["SaveLocation"].Substring(0, e.InputParameters["SaveLocation"].LastIndexOf("/")));
Get Value from a field:
private string GetFormFieldValue(string fieldName)
{
string fieldValue = string.Empty;
try
{
XPathNavigator myNav = MainDataSource.CreateNavigator().SelectSingleNode(fieldName, NamespaceManager);
if (myNav != null)
fieldValue = myNav.Value; ;
if (string.IsNullOrEmpty(fieldValue))
return string.Empty;
else
return fieldValue;
}
catch { return fieldValue; }
}
Set Value for a field:
private void SetFormFieldValue(string fieldName, string fieldValue)
{
XPathNavigator myNav = MainDataSource.CreateNavigator().SelectSingleNode(fieldName, NamespaceManager);
if (myNav != null)
myNav.SetValue(fieldValue); ;
}
Submit form programmatically:
FileSubmitConnection fileSubmit = (FileSubmitConnection)this.DataConnections["SharePoint Library Submit"]; // SharePoint Library Submit is name of my submit connection.
// Relative the SharePoint Submit location to current SharePoint site.
fileSubmit.FolderUrl = GetFormFieldValue("/my:ChangeOrder/my:SectionHide/my:ListURL"); // This is form saving path, Where I want to save my form programmatically.
fileSubmit.Execute();
Execute Query Programmatically:
DataSources["Project Category"].QueryConnection.Execute(); //Project Category is name of my data connection.
DataSources["Users"].QueryConnection.Execute();//Users is name of my data connection.
Programmatically read rows from reapting table :
//I have added a section called ServicesSection then a reaping table with name of ServiceTask and then provided name to the reapting group-ServiceTaskTable. I have created three fields in this reaping table.
XPathNavigator root = MainDataSource.CreateNavigator();
XPathNodeIterator rows = root.Select("/my:myFields/my:ServicesSection/my:ServiceTask/my:ServiceTaskTable", NamespaceManager);
while (rows.MoveNext())
{
sHrs = GetFieldValue(rows.Current, "my:Hours");
sMinutes = GetFieldValue(rows.Current, "my:Minutes");
sActivityDetails = GetFieldValue(rows.Current, "my:ActivityDetails");
}
Comments