2014-04-18 41 views

回答

1

你可以通過網絡服務。如果您在SharePoint 2013上 - 它具有REST服務。只需做出PUT請求並完成。如果它是SharePoint 2010 - 您需要SOAP服務的請求。 有一個關於在SharePoint 2013上傳的文章:Uploading Files Using the REST API 有大約2010版:Upload documents to SharePoint 2010

+0

謝謝您的回答。但「上傳文檔到SharePoint 2010」不是java.server是SharePoint 2010. –

+0

@love_mark,你可以在java中使用soap服務嗎?谷歌說,這是可能的。 –

1
public int uploadFile(String directoryPath, String file_path){ 
     if (siteHost.isEmpty() || !isLogin) return ERROR_LOGIN; 

     String webserviceUrl = "http://site:port/_vti_bin/listdata.svc/SharedDocuments"; 
     String slug = "http://site:port/Shared%20Documents/filename"; 

     File file = new File(file_path); 
     if (file == null) return ERROR_FILE; 
     String file_name = file.getName(); 
     ContentBody filebody = new FileBody(file); 
     HttpPost post = new HttpPost(webserviceUrl); 

     post.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false); 
     post.setHeader("Content-Type","multipart/form-data"); 
     post.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); 
     post.setHeader("Accept-Encoding", "gzip, deflate"); 
     post.setHeader("Accept-Language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3"); 
     post.setHeader("User-Agent", "Mozilla/5.0 (Android; Mobile; rv:28.0) Gecko/28.0 Firefox/28.0"); 
     post.addHeader("Slug",slug); 

     MultipartEntity multipartContent = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); 
     multipartContent.addPart(file_name, filebody); 
     post.setEntity(multipartContent);  ; 

     try { 
      HttpResponse response = defaultHttpClient.execute(post); 
      int resCode = response.getStatusLine().getStatusCode(); 
      if (resCode != 201) return ERROR_UPLOAD; 
     } catch (IOException e) { 
      e.printStackTrace(); 
      return ERROR_UPLOAD; 
     } 

     return ERROR_SUCCESS; 
    } 
+0

你能上傳Sharepoint上的文件嗎? –

相關問題