2011-09-30 81 views
0

希望你能提供帮助。我正在使用支持浏览器的InfoPath 2010表单,该表单位于SharePoint网站(2007和2010)上的文档库中。在这种形式下,有一个重复的表格,其中包含需要为报告目的而捕获的数据。我选择的解决方案是使用内置的SharePoint lists.asmx Web Service将重复表中的行写入相同网站集中理性SharePoint网站上的单独列表。我使用这里的步骤http://msdn.microsoft.com/en-us/library/cc162745(v=office.12).aspx作为我的基准。以浏览器启用的形式提交重复InfoPath表到Sharepoint列表

从InfoPath表单客户端网站直接运行时,我已经完成了所有设置和工作。打开表单,并在提交时将重复表中的行写入SharePoint列表中,没有任何问题。但是,一旦我通过中央管理和测试部署表单,重复表中的任何行都不会写入列表。没有错误或任何可以指示代码有问题的地方,并且用于指示是否已经上传行的布尔字段被设置为true。

我的第一个想法是,某处存在权限问题。也许当从客户端调用服务时,它会传递我的凭据,但是当通过文档库从服务器运行时,它使用的是不同的东西?它不应该使用用于访问SharePoint的凭据(这也是我的AD凭据)?在代码中调用lists.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"); 
        } 

       } 
      } 
+0

请发表您的代码示例 – int32

回答

0

嗯,我不确定这是否答案本身,但我相信这个问题与网站的安全性有关。我通过使用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(); 
          } 
         } 
        } 
0

我不确定代码中部署和调用列表Web服务时代码不起作用。不过我建议你尝试调试它来找到问题的根源:

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

请尝试了这一点,并通过它一步,看它是否经过代码预期。

+0

谢谢您的提示。我会给这个镜头并且回传结果。 – TenaciousTom

+0

我能够按照您提供的第2步中提供的链接中的步骤进行操作。之后,看起来似乎缺少了某些内容。验证包含PDB文件后,我重命名已发布的XSN文件。我转到SharePoint网站集的中央管理员并上载表单。然后,我导航到使用表单的SharePoint列表。我打开窗体的.cs文件,附加到进程,附加到托管代码,检查显示所有进程和所有会话,并且没有列出w3wp.exe进程。有什么我失踪? – TenaciousTom

+0

你在Sharepoint服务器本身上运行Visual Studio吗? –

相关问题