So I'm trying to upload a document to a sharepoint site using a Java implementation of the MOSS 2007 Web Services API. I've managed to upload the file to the site, which I can confirm by manually viewing the destination URL. However, when using the all documents view the file is not visible. I feel like it has something to do with how I'm setting the meta-data, but I'm not sure.
Here's my code for reference:
public static void main(String[] args) {
JCopy copy = new JCopy("http://somespsite", "user", "pass");
try {
File f = new File("c:/test.txt");
byte[] b = new byte[(int) f.length()];
FileInputStream fileInputStream = new FileInputStream(f);
fileInputStream.read(b);
List<String> dest = new ArrayList<String>();
dest.add("http://somespsite/Test Repository/Forms/test.txt");
List< FieldInformation > fields = new ArrayList<FieldInformation>();
FieldInformation field = new FieldInformation();
field.setType(FieldType.TEXT);
field.setDisplayName("Test2");
field.setInternalName("Test2");
field.setId(java.util.UUID.randomUUID().toString());
field.setValue(field.getValue());
copy.copyIntoItems(
"c:/test.txt",
dest,
fields,
b,
null);
}catch (Exception e) {
e.printStackTrace();
}
}
class JCopy {
public int copyIntoItems(
String sourceUrl,
List<String> destinations,
List<FieldInformation> fields,
byte[] stream,
List<CopyResult> results )
{
DestinationUrlCollection destinationUrls = new DestinationUrlCollection();
for(String s : destinations)
destinationUrls.addString(s);
FieldInformationCollection fieldsInput = new FieldInformationCollection();
for(FieldInformation f : fields)
fieldsInput.addFieldInformation(f);
Holder<Long> copyIntoItemsResult = new Holder<Long>(Long.valueOf(-1));
Holder<CopyResultCollection> resultsOutput = new Holder<CopyResultCollection>((CopyResultCollection) results);
try {
port.copyIntoItems(sourceUrl, destinationUrls, fieldsInput, stream, copyIntoItemsResult, resultsOutput);
results = resultsOutput.value.getCopyResult();
} catch (Exception e) {
e.printStackTrace();
}
return copyIntoItemsResult.value.intValue();
}}
port is an instance of the stubs generated by Netbeans using JDK 1.6.