2012-06-14 39 views
0

因此,我試圖使用MOSS 2007 Web服務API的Java實現將文檔上傳到SharePoint站點。我設法將文件上傳到網站,我可以通過手動查看目標網址來進行確認。但是,使用全部文檔查看文件時不可見。我覺得這與我如何設置元數據有關,但我不確定。Java Web服務上傳後隱藏的Sharepoint文檔

這裏是我的代碼,以供參考:

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(); 
}} 

端口使用JDK 1.6的Netbeans中產生的存根的一個實例。

回答

1

您正在將文檔上傳到錯誤的位置。

文件存儲在文檔庫中。文檔庫有一組默認的表格來顯示和編輯每個文件的屬性。具有適當權限的用戶可以自定義或添加新權限。

表格放置在「Forms」文件夾的每個文檔庫中。所有視圖都顯示庫本身的內容,而不顯示Forms文件夾。

我假設「Test Repository」是您的文檔庫,在這種情況下,您將文件test.txt上傳到「Forms」目錄而不是「Test Repository」本身。

只需將您的url更改爲指向「Test Repository」而不是「Test Repository/Forms」。

+0

太棒了。馬上處理這個問題。 – WLPhoenix

相關問題