2009-04-07 105 views

回答

-2

爲什麼不只是使用 wget.exe <url> 。您可以將該行放入批處理文件中,並通過Windows調度程序運行該行。

0

Sharepoint中文檔的鏈接應該是一個靜態URL。在任何解決方案中使用該URL來獲取計劃中的文件。

+0

有沒有軟件可以做到這一點? – 2009-04-07 14:54:32

2

你也可以這樣做:

                        
                          try 
     { 
      using (WebClient client = new WebClient()) 
      { 
       client.Credentials = new NetworkCredential("username", "password", "DOMAIN"); 
       client.DownloadFile(http_path, path);      
      } 
     } 
     catch (Exception ex) 
     { 
      MessageBox.Show("Error: " + ex.Message); 
     } 

                        
                      
5

是的,它可以從SharePoint下載文件。 一旦你有文件的URL,它可以使用HttpWebRequest和HttpWebResponse下載。

附加示例代碼

                        
                          DownLoadDocument(string strURL, string strFileName) 
    { 
     HttpWebRequest request; 
     HttpWebResponse response = null; 

      request = (HttpWebRequest)WebRequest.Create(strURL); 
      request.Credentials = System.Net.CredentialCache.DefaultCredentials; 
      request.Timeout = 10000; 
      request.AllowWriteStreamBuffering = false; 
      response = (HttpWebResponse)request.GetResponse(); 
      Stream s = response.GetResponseStream(); 

      // Write to disk 
      if (!Directory.Exists(myDownLoads)) 
      { 
       Directory.CreateDirectory(myDownLoads); 
      } 
      string aFilePath = myDownLoads + "\\" + strFileName; 
      FileStream fs = new FileStream(aFilePath, FileMode.Create); 
      byte[] read = new byte[256]; 
      int count = s.Read(read, 0, read.Length); 
      while (count > 0) 
      { 
       fs.Write(read, 0, count); 
       count = s.Read(read, 0, read.Length); 
      } 

      // Close everything 
      fs.Close(); 
      s.Close(); 
      response.Close(); 

    } 

                        
                      

您還可以使用複製服務的API的GetItem下載文件。

                        
                           string aFileUrl = mySiteUrl + strFileName; 
     Copy aCopyService = new Copy(); 
     aCopyService.UseDefaultCredentials = true; 
     byte[] aFileContents = null; 
     FieldInformation[] aFieldInfo; 
     aCopyService.GetItem(aFileUrl, out aFieldInfo, out aFileContents); 

                        
                      

該文件可以作爲字節數組檢索。

相關問題