C# – Submitting Repeating InfoPath Table to Sharepoint list in Browser Enabled Form

cinfopathsharepointweb services

Hopefully you can help. I am working on a Browser Enabled InfoPath 2010 form that lives in a Document Library on a SharePoint site (2007 and 2010). In this form there is a repeating table with data that needs to be captured for reporting purposes. The solution I have chosen is to use the built in SharePoint lists.asmx Web Service to write the lines in the repeating table to a separate list on the sane SharePoint site, in the same site collection. I used the steps here, http://msdn.microsoft.com/en-us/library/cc162745(v=office.12).aspx, as my baseline.

I have gotten everything set up and working when run directly from the InfoPath form client site. The form opens and, on submit, the rows in the repeating table are written to the SharePoint list without any problems. However, once I deploy the form through Central Admin and test, none of the rows in the repeating table are getting written to the list. There are no errors or anything to indicate a problem with the code, and a boolean field used to indicate whether or not a row has been uploaded is set to true.

My first thought is that there is a problem with the permissions somewhere. Maybe when the service is called from client side it passes my credentials but when run from the server through the Document Library it's using something different? Shouldn't it use the credentials that are used to gain access to the SharePoint (which are also my AD credentials)? Is there a way to specify the use of the current users AD credentials when calling the lists.asmx web service in the code?

Anyway, not really sure where else to go with this. Any searching I do comes up with the same how two documentation on submitting to a SharePoint list in general. Any help would be greatly appreciated. Below is the code I am using to accomplish this.

if (MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:ShippingInformation/my:ShipDate", NamespaceManager).Value != "")
            {
                // If Ship Date is not blank, upload items in Material used to SP List where ForQuote is False
                // Quote Number, RMA Number, Ship Date, Unit S/N,

                // Create a WebServiceConnection object for submitting 
                // to the Lists Web service data connection.
                WebServiceConnection wsSubmit =
                   (WebServiceConnection)this.DataConnections["Material Web Service Submit"];

                //Create XPathNodeIterator object for the new Material Lines
                XPathNodeIterator MaterialLines = this.MainDataSource.CreateNavigator().Select("/my:myFields/my:RepairQuote/my:QuoteLines/my:QuoteLine", NamespaceManager);
                int lineCount = 0;

                foreach (XPathNavigator NewLines in MaterialLines)
                {
                    lineCount += 1;
                    if (NewLines.SelectSingleNode(".//my:ForQuote", NamespaceManager).Value == "false" && NewLines.SelectSingleNode(".//my:LineSubmitted", NamespaceManager).Value == "false")
                    {
                        // Set the values in the Add List Item Template 
                        // XML file using the values in the new row.
                        DataSources["AddListItemTemplate"].CreateNavigator().SelectSingleNode("/Batch/Method/Field[@Name='Title']", NamespaceManager).SetValue(NewLines.SelectSingleNode(".//my:lineItem", NamespaceManager).Value);
                        DataSources["AddListItemTemplate"].CreateNavigator().SelectSingleNode("/Batch/Method/Field[@Name='RMANumber']", NamespaceManager).SetValue(MainDataSource.CreateNavigator().SelectSingleNode("./my:myFields/my:EntitlementContainer/my:RMANumber", NamespaceManager).Value);
                        DataSources["AddListItemTemplate"].CreateNavigator().SelectSingleNode("/Batch/Method/Field[@Name='UnitSerialNumber']", NamespaceManager).SetValue(MainDataSource.CreateNavigator().SelectSingleNode("./my:myFields/my:EntitlementContainer/my:serialNumber", NamespaceManager).Value);
                        DataSources["AddListItemTemplate"].CreateNavigator().SelectSingleNode("/Batch/Method/Field[@Name='ShipDate']", NamespaceManager).SetValue(MainDataSource.CreateNavigator().SelectSingleNode("./my:myFields/my:ShippingInformation/my:ShipDate", NamespaceManager).Value);
                        DataSources["AddListItemTemplate"].CreateNavigator().SelectSingleNode("/Batch/Method/Field[@Name='OrderType']", NamespaceManager).SetValue(MainDataSource.CreateNavigator().SelectSingleNode("./my:myFields/my:RepairQuote/my:orderType", NamespaceManager).Value);
                        DataSources["AddListItemTemplate"].CreateNavigator().SelectSingleNode("/Batch/Method/Field[@Name='QuoteNumber']", NamespaceManager).SetValue(MainDataSource.CreateNavigator().SelectSingleNode("./my:myFields/my:RepairQuote/my:quoteNumber", NamespaceManager).Value);
                        DataSources["AddListItemTemplate"].CreateNavigator().SelectSingleNode("/Batch/Method/Field[@Name='LineQuantity']", NamespaceManager).SetValue(NewLines.SelectSingleNode(".//my:lineQuantity", NamespaceManager).Value);
                        DataSources["AddListItemTemplate"].CreateNavigator().SelectSingleNode("/Batch/Method/Field[@Name='LineNumber']", NamespaceManager).SetValue(lineCount.ToString());

                        // Set the value of Cmd attribute to "New".
                        DataSources["AddListItemTemplate"].CreateNavigator().SelectSingleNode("/Batch/Method/@Cmd", NamespaceManager).SetValue("New");

                        // Submit the new row.
                        wsSubmit.Execute();
                        NewLines.SelectSingleNode(".//my:LineSubmitted", NamespaceManager).SetValue("true");
                    }

                }
            }

Best Answer

I'm unsure why the code doesn't work when you deploy and call the lists web service in code. However I would suggest you to try debugging it to get to the root of the problem:

Step by Step – Debug InfoPath 2010 Forms Deployed on SharePoint 2010 Using Visual Studio 2010

Please try this out and step through it to see if it goes through the code as expected.

Related Topic