使用CopyIntoItems上传文档时无法更新查找字段

时间:2009-12-16 15:02:10

标签: web-services sharepoint-2007

我正在尝试使用Copy.asmx webservice,CopyIntoItems方法从本地计算机上传文档。我可以成功上传文档和DateTime属性,但我无法更新文档库的查找属性。我正在使用带有sp2的MOSS 2007

我使用的代码如下所示:

string[] destinationUrls = { Uri.EscapeUriString(destinationUrl) };

CopySharepointService.FieldInformation dateInformation = new CopySharepointService.FieldInformation();
dateInformation.DisplayName = "Date";
dateInformation.Type = CopySharepointService.FieldType.DateTime;
dateInformation.Value = DateTime.Today.ToString();

CopySharepointService.FieldInformation fundInformation = new CopySharepointService.FieldInformation();
fundInformation.DisplayName = "Fund";
fundInformation.Type = CopySharepointService.FieldType.Lookup;
fundInformation.Id = new Guid(fundGuidItem); // This is the GUID of the field being updated in the document library
fundInformation.Value = "1";

CopySharepointService.FieldInformation[] info = { dateInformation, fundInformation };            
CopySharepointService.CopyResult[] result;    
CopySharepointService.CopySoapClient CopyService2007 = new CopySoapClient("CopySoap");

CopyService2007.ClientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
CopyService2007.CopyIntoItems(destinationUrl, destinationUrls, info, fileData, out result);

文档已成功上传,但查找字段未更新

有人可以帮忙吗?

3 个答案:

答案 0 :(得分:4)

我刚发现这个帖子:

“不幸的是,CopyIntoItems不会将信息放入”File“,”Computed“或”Lookup“类型的字段中.Web服务使用SPCopy类的CopyIntoItem,它调用一个名为FieldShouldBeCopiedTo的私有方法。此方法包含修复Lookup字段的逻辑被复制。“

http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/2fdc9933-ddb8-446f-80ad-6c8e17dfdb6f

我有时讨厌SharePoint。

答案 1 :(得分:1)

无法做到这一点;唯一的选择是重新连接,获取列表项本身并以这种方式更新元数据。请记住:查找字段需要使用number;#的格式 - 所以,如果您是,那么数据是否为:

12;#Some Option

在Xml批量更新中使用12;#

答案 2 :(得分:0)

不幸的是,您必须通过UpdateListItems跟进来设置所有“有趣”的元数据。

来自链接中的示例:

Web_Reference_Folder.Lists listService = new Web_Reference_Folder.Lists();
listService.Credentials= System.Net.CredentialCache.DefaultCredentials;

string strBatch = "<Method ID='1' Cmd='Update'>" + 
    "<Field Name='ID'>4</Field>" +
    "<Field Name='Field_Number'>999</Field></Method>" +
    "<Method ID='2' Cmd='Update'><Field Name='ID' >6</Field>" +
    "<Field Name='Field_DateTime'>
        2003-11-11T09:15:30Z</Field></Method>"; 

XmlDocument xmlDoc = new System.Xml.XmlDocument();

System.Xml.XmlElement elBatch = xmlDoc.CreateElement("Batch");

elBatch.SetAttribute("OnError","Continue");
elBatch.SetAttribute("ListVersion","1");
elBatch.SetAttribute("ViewName",
    "0d7fcacd-1d7c-45bc-bcfc-6d7f7d2eeb40");

elBatch.InnerXml = strBatch;

XmlNode ndReturn = listService.UpdateListItems("List_Name", elBatch);

MessageBox.Show(ndReturn.OuterXml);