Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm trying to upload a document to a document library using the SP 2010 SOAP copy web service from Java.

Any idea how to do this in Java?

Here's the code I have so far:

String[] destinationUrls = {mySiteUrl + "/" + listName + "/" + fileName};

// Set up the metadata
FieldInformation titleInfo = new FieldInformation();
titleInfo.setDisplayName("Title");
titleInfo.setInternalName("Title");
titleInfo.setType(FieldType.TEXT);
titleInfo.setValue("DocumentTitle");

// Content type meta
FieldInformation contentTypeInfo = new FieldInformation();
contentTypeInfo.setDisplayName("Content Type");
contentTypeInfo.setInternalName("Content Type");
contentTypeInfo.setType(FieldType.CHOICE);
contentTypeInfo.setValue("Document");

FieldInformation[] metadata = { titleInfo, contentTypeInfo };

// Copy the new file to the portal document list
Long copyIntoResult;
CopyResult[] result;

client.copyIntoItems("http://null", destinationUrls, metadata, fileBytes, copyIntoResult, result);

But Eclipse reports that my use of copyIntoItems "in the type CopySoap is not applicable for the arguments". Obviously, my supplied arguments are incorrect.

The WSDL-generated signature for the copyIntoItems() method looks like:

copyIntoItems(String, DestinationUrlCollection, FieldInformationCollection, byte[], Holder<Long>, Holder<CopyResultCollection>);

But those Collection types and Holder only supply protected accessors, i.e. no way to set input state.

Can anyone help me solve this problem?

share|improve this question
    
Related question on SO stackoverflow.com/questions/31868/… –  Kit Menke Jun 24 '11 at 18:03
    
Ooh, thanks @Kit. –  retrodrone Jun 24 '11 at 22:07

1 Answer 1

up vote 1 down vote accepted

I didn't read the generated code comments close enough. Here's the solution:

DestinationUrlCollection destinationUrls = new DestinationUrlCollection();
destinationUrls.getString().add(_siteUrl + listName + "/" + fileName);

// Set up the metadata
// Remark: don't set the Name field, because this is the name of the document
FieldInformation titleInfo = new FieldInformation();
// (same as before)

// Content type meta
FieldInformation contentTypeInfo = new FieldInformation();
// (same as before)

FieldInformationCollection metadata = new FieldInformationCollection();
metadata.getFieldInformation().add(titleInfo);
metadata.getFieldInformation().add(contentTypeInfo);

// Copy the new file to the portal document list
Holder<Long> copyIntoResult = new Holder<Long>();
Holder<CopyResultCollection> result = new Holder<CopyResultCollection>();

client.copyIntoItems("http://null", destinationUrls, metadata, fileBytes, copyIntoResult, result);

But it's soo quirky. destinationUrls.getString().add()? And Holder<Long> as opposed to Long?

share|improve this answer
    
Can you put your full code here. I am trying exactly same and I am a little new to Java. Thank you Bobby –  user4313 Aug 2 '11 at 18:47
    
How to upload a large document to SharePoint from mobile device (where it is not enough RAM to store whole "fileBytes")? Is it possible to divide the fileBytes on parts? –  surlac Nov 9 '12 at 13:36
    
Thanks a ton, this solution was really helpful :-) –  user19272 Sep 3 '13 at 7:40
    
Could you upload the full class? :( Would really appreciate it as it's exactly what I'm trying to accomplish. –  Shelby. S Jul 10 at 12:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.