Visit our SharePoint Forum

SharePoint developer? Submit Yourself as Freelancer

Saturday, November 15, 2008

Tips on Programming with InfoPath

Using WCF with Infopath

WCF service was used to fill-in the Drop-downs in infopath.

//Read the Service url from config file into LookupServiceUrlField
strServiceUrl = navigator.SelectSingleNode("/my:myFields/my:LookupServiceUrl", NamespaceManager).Value;

if (strServiceUrl != "")
{
EndpointAddress address = new EndpointAddress(strServiceUrl);
BasicHttpBinding binding = new BasicHttpBinding();

ChannelFactory factory = new ChannelFactory(binding, address);

ILookupItemManager svc = factory.CreateChannel();
LookupItemsByTypeResponse response = new LookupItemsByTypeResponse();
LookupItemsByTypeRequest request = new LookupItemsByTypeRequest();

------------------------------------------------------------------------------------
Programmatically Add Item in the Drop-down

1. Add a Repeating group (parent).
2. Add another Repeating group under the above group with same name as dropdown + row (thats just the way i am doing it).
3. Add two fields dropdown name+ rowvalue and dropdown name + rowdescription under it.
4. Bind the Original Dropdown to a repeating group.(with rowvalue and rowdescription).

Use AddItem method below to dynamically add the values in dropdown

strDropDownName -> Name of the Original Drop-down
root -> RootNavigation
parent -> root.SelectSingleNode("//my:myFields/" + strDropDownName, NamespaceManager); //pointer to repeating group
row -> XPathNavigator row = root.SelectSingleNode("//my:myFields/" + strDropDownName + "/" + strDropDownName + "Row", NamespaceManager); // group inside repeating group
Itemid -> from WCF
ItemName-> from WCF

private void AddItem(string strDropDownName, XPathNavigator root, XPathNavigator parent, XPathNavigator row, int itemId, string itemName)
{
XPathNavigator newNode = row.Clone();
if (itemId == -1)
{
newNode.SelectSingleNode("//my:myFields/" + strDropDownName + "/" + strDropDownName + "Row/" + strDropDownName + "RowValue", NamespaceManager).InnerXml = "";
}
else
newNode.SelectSingleNode("//my:myFields/" + strDropDownName + "/" + strDropDownName + "Row/" + strDropDownName + "RowValue", NamespaceManager).InnerXml = itemId.ToString();
newNode.SelectSingleNode("//my:myFields/" + strDropDownName + "/" + strDropDownName + "Row/" + strDropDownName + "RowDescrip", NamespaceManager).InnerXml = itemName;
parent.AppendChild(newNode);
}

1 comments:

Computer Science said...
This comment has been removed by a blog administrator.

SharePoint Programming