Monday, August 29, 2011

InfoPath Interview Questions

Q. How do I retrieve the value of an InfoPath field through code?
Ans.
XPathNavigator nav = MainDataSource.CreateNavigator();
string fieldValue = nav.SelectSingleNode("//my:field1", NamespaceManager).Value;

Q. How do I set the value of an InfoPath field through code?
Ans.
XPathNavigator nav = MainDataSource.CreateNavigator();
nav.SelectSingleNode("//my:field1", NamespaceManager).SetValue("myValue");

Q. How do I call a web service through code?
Ans.
// Create an XPathNavigator object to navigate the data source of the web service
XPathNavigator nav = DataSources["HelloWorld"].CreateNavigator();

// Set the value of the parameter to pass to the web service
nav.SelectSingleNode("//dfs:queryFields/tns:HelloWorld/tns:name", NamespaceManager).SetValue("myValue");

// Call the web service
DataSources["HelloWorld"].QueryConnection.Execute();
// Retrieve the results returned by the web service
string results = nav.SelectSingleNode("//dfs:dataFields/tns:HelloWorldResponse/tns:HelloWorldResult", //NamespaceManager).Value;
//where HelloWorld is the name of a data connection to a web service.


No comments:

Post a Comment

Featured Post

Protect an API by using OAuth 2.0 with Azure Active Directory and API Management

Protect an API by using OAuth 2.0 with Azure Active Directory and API Management https://docs.microsoft.com/en-us/azure/api-management/api-...

Popular posts