0
votes

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.

1

1 Answers

1
votes

You are uploading the document to the wrong location.

Files are stored in document libraries. Document libraries have a set of default forms to display and edit the properties of each file. Users with appropriate rights can customize them or add new ones.

The forms are placed in the "Forms" folder of each document library. All views display the contents of the library itself, never the Forms folder.

I assume "Test Repository" is your document library in which case you are uploading the file test.txt to the "Forms" directory instead of "Test Repository" itself.

Just change your url to point to "Test Repository" instead of "Test Repository/Forms".