簡體   English   中英

在啟用瀏覽器的表單中將重復的InfoPath表提交到Sharepoint列表

[英]Submitting Repeating InfoPath Table to Sharepoint list in Browser Enabled Form

希望您能提供幫助。 我正在使用一個啟用了瀏覽器的InfoPath 2010表單,該表單位於SharePoint網站(2007和2010)上的文檔庫中。 在此表單中,有一個重復表,其中包含需要出於報告目的而捕獲的數據。 我選擇的解決方案是使用內置的SharePoint list.asmx Web服務將重復表中的行寫入同一網站集中同等SharePoint網站上的單獨列表中。 我使用此處的步驟http://msdn.microsoft.com/zh-cn/library/cc162745(v=office.12).aspx作為我的基准。

直接從InfoPath表單客戶端站點運行時,我已經完成所有設置並可以正常工作。 表單打開,提交后,重復表中的行被寫入SharePoint列表,沒有任何問題。 但是,一旦我通過Central Admin部署並測試了表單,重復表中的所有行都不會寫入列表。 沒有錯誤或任何指示代碼有問題的信息,並且用於表示是否已上傳行的布爾值字段設置為true。

我首先想到的是某處的權限存在問題。 也許從客戶端調用該服務時會傳遞我的憑據,但是從服務器通過文檔庫運行時會使用其他內容嗎? 它不應該使用用於訪問SharePoint的憑據(也是我的AD憑據)嗎? 在代碼中調用list.asmx Web服務時,是否可以指定使用當前用戶AD憑據的方法?

無論如何,不​​是很確定與此相關的其他地方。 一般而言,我所做的任何搜索都具有與提交到SharePoint列表的兩個文檔相同的方式。 任何幫助將不勝感激。 以下是我用來完成此操作的代碼。

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");
                    }

                }
            }

我不確定為什么在部署和調用代碼中的列表Web服務時代碼不起作用。 但是我建議您嘗試調試它以解決問題的根源:

循序漸進–使用Visual Studio 2010調試在SharePoint 2010上部署的InfoPath 2010表單

請嘗試一下並逐步解決它,看看它是否按預期方式通過了代碼。

好吧,我不確定這是否是答案,但我認為問題與站點的安全性有關。 我通過使用SharePoint對象模型而不是Web服務來創建列表項來解決此問題(請參閱http://www.bizsupportonline.net/browserforms/how-to-use-sharepoint-object-model-submit-data- infopath-browser-form-sharepoint-list.htm )。 通過SharePoint對象模型,我可以使用AllowUnsafeUpdates。 另外,我花了很多時間來設置Web服務,包括數據連接,CAML文件等。但是,這種方式只花了幾分鍾。 經驗教訓,請盡可能使用SharePoint對象模型。

foreach (XPathNavigator NewLines in MaterialLines)
                {
                    lineCount += 1;
                    if (NewLines.SelectSingleNode(".//my:ForQuote", NamespaceManager).Value == "false" && NewLines.SelectSingleNode(".//my:LineSubmitted", NamespaceManager).Value == "false")
                    {

                        using (SPSite site = SPContext.Current.Site)
                        {
                            if (site != null)
                            {
                                using (SPWeb web = site.OpenWeb())
                                {
                                    // Turn on AllowUnsafeUpdates on the site
                                    web.AllowUnsafeUpdates = true;

                                    // Update the SharePoint list based on the values
                                    // from the InfoPath form
                                    SPList list = web.GetList("/Lists/InfoPathRtpItems");

                                    if (list != null)
                                    {
                                        SPListItem item = list.Items.Add();
                                        item["Title"] = NewLines.SelectSingleNode(".//my:lineItem", NamespaceManager).Value;
                                        item["RMANumber"] = MainDataSource.CreateNavigator().SelectSingleNode("./my:myFields/my:EntitlementContainer/my:RMANumber", NamespaceManager).Value;
                                        item["UnitSerialNumber"] = MainDataSource.CreateNavigator().SelectSingleNode("./my:myFields/my:EntitlementContainer/my:serialNumber", NamespaceManager).Value;
                                        item["ShipDate"] = MainDataSource.CreateNavigator().SelectSingleNode("./my:myFields/my:ShippingInformation/my:ShipDate", NamespaceManager).Value;
                                        item["OrderType"] = MainDataSource.CreateNavigator().SelectSingleNode("./my:myFields/my:RepairQuote/my:orderType", NamespaceManager).Value;
                                        item["QuoteNumber"] = MainDataSource.CreateNavigator().SelectSingleNode("./my:myFields/my:RepairQuote/my:quoteNumber", NamespaceManager).Value;
                                        item["LineQuantity"] = NewLines.SelectSingleNode(".//my:lineQuantity", NamespaceManager).Value;
                                        item["LineNumber"] = lineCount.ToString();
                                        item.Update();
                                    }

                                    // Turn off AllowUnsafeUpdates on the site
                                    web.AllowUnsafeUpdates = false;

                                    // Close the connection to the site
                                    web.Close();
                                }

                                // Close the connection to the site collection
                                site.Close();
                            }
                        }
                    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM