我希望有人可以帮助我。我正在使用自定义SharePoint 2007列表构建的Contact Manager,其中Silverlight 4 UI嵌入在内容编辑器Web部件中。
我目前能够从列表中检索数据并将其显示在UI上的数据网格中,一切运行良好。
现在我尝试使用以下代码添加将新项目添加到列表的功能,但项目不会保存。
我使用Debug远程调试了以下代码 - >附加到Process选项,一切似乎执行成功,没有任何错误,但它不会将项目保存到SharePoint。
为了简化并获得有效的插入功能,我将所有SharePoint系列更改为单行文本,但注释(多行)除外,并且不需要任何文件。
sharepoint站点确实需要Windows身份验证,但它似乎正常工作,因为我能够显示它以及使用标准SharePoint表单手动添加新项目。
最后,我在底部为Batch元素添加了xml,我在debuging时将其复制为输出。
如果我可能遗失任何其他信息,请告诉我。
提前感谢您愿意提供的任何帮助。
查尔斯
public string sharepoint_soap_namespace = "http://schemas.microsoft.com/sharepoint/soap/";
public string sharepoint_rowset_namespace = "#RowsetSchema";
public string service_lists_url = "http://myDomain/_vti_bin/lists.asmx";
public string listName = "MyContacts";
public void TestCreateContact()
{
Uri serviceUri = new Uri(service_lists_url);
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
binding.MaxReceivedMessageSize = 2147483647; // This has to be the same as in the ServiceReferences.ClientConfig file.
EndpointAddress endpoint = new EndpointAddress(serviceUri);
ListsSoapClient testCreateClient = new ListsSoapClient(binding, endpoint);
XElement batch = new XElement("batch",
new XElement("Method",
new XAttribute("ID", "1"),
new XAttribute("Cmd", "New"),
CreateFieldElement("ows_ID", "New"),
CreateFieldElement("ows_Title", "John"),
CreateFieldElement("ows_SupportFor","USA"),
CreateFieldElement("ows_LastName","Doe")
));
testCreateClient.UpdateListItemsCompleted +=
new EventHandler<UpdateListItemsCompletedEventArgs>(createSoapClient_UpdateListItemsCompletedEventArgs);
testCreateClient.UpdateListItemsAsync(listName, batch);
testCreateClient.CloseAsync();
}
private XElement CreateFieldElement(string fieldName, string fieldValue)
{
XElement element = new XElement("Field",
new XAttribute("Name", fieldName),
fieldValue);
return element;
}
答案 0 :(得分:0)
快速更新,让每个人都知道我能够回答我自己的问题。 似乎在批处理XElement中我使用了错误的字段名称。
CreateFieldElement( “ows_SupportFor”, “USA”),
我使用“ows_SupportFor”代替“SupportFor”而没有“ows_”前缀。
干杯, 查尔斯