3

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?

1

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?

  • 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
  • Could you upload the full class? :( Would really appreciate it as it's exactly what I'm trying to accomplish. – Shelby. S Jul 10 '14 at 12:58
0

You should not have SPACE in Internal Name. Please see below the corrected content.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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