2009-10-14 48 views

回答

3

Google文檔爲此提供了一個API。

Google文檔列表數據API允許客戶端應用程序以編程方式訪問 並處理存儲在Google文檔中的用戶數據。

檢查它是documentation,它有例子和一切你需要開發的東西基於谷歌文檔。

1
using System; 
using System.IO; 
using System.Net; 
using Google.Documents; 
using Google.GData.Client; 

namespace Google 
{ 
    class Program 
    { 
     private static string applicationName = "Testing"; 

     static void Main(string[] args) 
     { 
      GDataCredentials credentials = new GDataCredentials("[email protected]", "password"); 
      RequestSettings settings = new RequestSettings(applicationName, credentials); 
      settings.AutoPaging = true; 
      settings.PageSize = 100; 
      DocumentsRequest documentsRequest = new DocumentsRequest(settings); 
      Feed<document> documentFeed = documentsRequest.GetDocuments(); 
      foreach (Document document in documentFeed.Entries) 
      { 
       Document.DownloadType type = Document.DownloadType.pdf; 

       Stream downloadStream = documentsRequest.Download(document, type); 

       Stream fileSaveStream = new FileStream(string.Format(@"C:\Temp\{0}.pdf", document.Title), FileMode.CreateNew); 

       if (fileSaveStream != null) 
       { 
        int nBytes = 2048; 
        int count = 0; 
        Byte[] arr = new Byte[nBytes]; 

        do 
        { 
         count = downloadStream.Read(arr, 0, nBytes); 
         fileSaveStream.Write(arr, 0, count); 

        } while (count > 0); 
        fileSaveStream.Flush(); 
        fileSaveStream.Close(); 
       } 
       downloadStream.Close(); 
      } 

     } 
    } 
} 
相關問題