簡體   English   中英

在線在Sharepoint中上傳文件

[英]Upload File in Sharepoint online

我想在共享點在線生成一個文件,但我仍然使用java.net.ConnectException: Connection timed out: connect異常java.net.ConnectException: Connection timed out: connect任何想法?

public static CopySoap getPort(String username, String password) {

    Copy service = new Copy();
    CopySoap port = service.getCopySoap();

    BindingProvider bp = (BindingProvider) port;

    bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
    bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
            "https://mysite/sites/_vti_bin/Copy.asmx");

    return port;
}
public static void createDocument(CopySoap port) throws Exception {
    String url = "https://mysite/sites/Documents partages/test.txt";
    String sourceUrl = "C:\\TEMP\\test.txt";     
    File file=new File(sourceUrl);
    DestinationUrlCollection urls = new DestinationUrlCollection();
    urls.getString().add(url);
    byte[] content = readAll(file);

    FieldInformation titleInfo = new FieldInformation ();
    titleInfo.setDisplayName("Title");
    titleInfo.setType(FieldType.TEXT);
    titleInfo.setValue("Test Doc");

    FieldInformationCollection infos = new FieldInformationCollection ();
    infos.getFieldInformation().add(titleInfo);

    CopyResultCollection results = new CopyResultCollection ();

    Holder<CopyResultCollection> resultHolder = new Holder<CopyResultCollection>(results);      

    Holder<Long> longHolder = new Holder<Long>(new Long(-1));       

    port.copyIntoItems(sourceUrl, urls, infos, content, longHolder, resultHolder);


    logger.debug("Long holder: " + longHolder.value);

    //do something meaningful here
    for (CopyResult copyResult : resultHolder.value.getCopyResult()) {              
        logger.debug("Destination: " + copyResult.getDestinationUrl());
        logger.debug("Error Message: " + copyResult.getErrorMessage());
        logger.debug("Error Code: " + copyResult.getErrorCode());
        if(copyResult.getErrorCode() != CopyErrorCode.SUCCESS)
            throw new Exception("Upload failed for: " + copyResult.getDestinationUrl() + " Message: " 
                    + copyResult.getErrorMessage() + " Code: " +   copyResult.getErrorCode() );

    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM