2011-10-14 1 views
0

에 업로드 파일 내가 SharePoint 사이트에 파일을 업로드하는 코드를 다음을 사용 http://10.0.0.22/_vti_bin/Copy.asmx가져 오기 오류 '개체 참조가 개체의 인스턴스로 설정되지 않았습니다'때 셰어

에서 자바 클래스를 생성하는 축 1.4 사용

private String uploadFile(String site, String username, String password, String library, String filename) { 
    String tag = ""; 
    try { 
     CopySoapStub stub = SharePointWSDL.newCopy(new URL(site + "/_vti_bin/Copy.asmx"), new CopyLocator()); 
     stub.setUsername(username); 
     stub.setPassword(password); 

     String name = (new File(filename)).getName(); 
     String tagPath = site + "/" + library + "/" + name; 
     FieldInformation[] fis = new FieldInformation[1]; 
     UnsignedIntHolder uih = new UnsignedIntHolder(); 
     CopyResultCollectionHolder crch = new CopyResultCollectionHolder(); 

     fis[0] = new FieldInformation(); 
     fis[0].setInternalName("Title"); 
     fis[0].setDisplayName(name); 
     fis[0].setType(FieldType.Text); 
     fis[0].setValue(name); 

     stub.copyIntoItems(null, new String[] { tagPath }, fis, readFile(filename), uih, crch); 
     boolean success = true; 
     for (int i = 0; i < crch.value.length; i++) { 
      if (CopyErrorCode._Success.equals(crch.value[i].getErrorCode().getValue())) continue; 
      logger.error(crch.value[i].getErrorCode().getValue() + " : " + crch.value[i].getErrorMessage()); 
      logger.info(crch.value[i].getDestinationUrl()); 
      success = false; 
     } 
     if (success) { 
      tag = tagPath; 
     } 
    } catch (Exception e) { 
     logger.error("", e); 
    } 
    return tag; 
} 

private byte[] readFile(String filename) { 
    File file = new File(filename); 
    byte[] tag = new byte[0]; 
    try { 
     tag = new byte[(int)file.length()]; 
     InputStream is = new FileInputStream(file);  
     int offset = 0; 
     int numRead = 0; 
     while (offset < tag.length && (numRead = is.read(tag, offset, tag.length - offset)) >= 0) { 
      offset += numRead; 
     }  
    } catch (Exception e) { 
     logger.error("", e); 
    } 
    return Base64.encode(tag).getBytes(); 
} 

'개체 참조가 개체의 인스턴스로 설정되지 않았습니다'오류가 발생합니다.

Axis 1.4에서 생성 된 클래스를 사용하여 SharePoint 사이트에 파일을 업로드하려면 어떻게해야합니까?

+0

코드의 어느 부분에서 오류가 발생하고 있습니까? – int32

+0

stub.copyIntoItems() '알 수 없음'오류 코드 및 '객체 참조가 객체의 인스턴스로 설정되지 않음'오류 메시지가있는 CopyResult를 반환합니다. –

답변

0

제 문제는 도메인 이름 대신 URL에서 IP를 사용한다는 것입니다. URL에 도메인 이름을 사용하면 코드가 올바르게 작동합니다.