5
votes

I am trying to upload a document from my local machine using the Copy.asmx webservice, the CopyIntoItems method. I can successfully upload the document and a DateTime property but I cannot update a lookup property of the document library. I am using MOSS 2007 with sp2

The code I am using is shown below:

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

The document is successfully uploaded but the lookup field is not updated

Can anyone please help?

3

3 Answers

4
votes

I just found this thread:

"Unfortunately, the CopyIntoItems will not put information into fields of "File", "Computed" or "Lookup" types. The web service uses the SPCopy class's CopyIntoItem which makes a call to a private method called FieldShouldBeCopiedTo. This method contains the logic prventing Lookup fields from being copied."

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

I hate SharePoint sometimes.

1
votes

No way to do it guys; the only alternative is to reconnect, get the list item itself and update the metadata that way. Remember: Lookup fields need to use the format of number;# - so if you if were if the data was:

12;#Some Option

Use 12;# in the Xml Batch Update.

0
votes

Unfortunately, you have to follow up with an UpdateListItems call to set all the "fun" metadata.

From the example in the link:

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