2011-10-13 102 views
2

我想知道如何將遠程文檔上傳到Google文檔,並且能夠使用Google文檔API使用Google文檔查看該文檔。使用Google文檔API

當我上傳一個文件,確實是回覆一個docid?這樣我可以使用它在上傳到我的帳戶後在線查看文檔。

比如我可以通過使用文檔ID

https://docs.google.com/Doc?docid=0AdmWTLTOoWVBZGd3ZDdtZmhfMGZ3czNrNmho

這將是可執行的PHP中打開我的賬戶的文件之一?我聽說它不再支持。我更喜歡PHP而不是C#,但是如果PHP不支持,我可以使用C#。

+0

你有沒有實際的文檔看呢? – ChrisBint

+0

我有,但我不明白。由於我是編程新手,請耐心等待 – user478636

回答

0

您必須使用以下代碼下載本地文件。

var request = new DocumentsRequest(settings); 
request.BaseUri = "https://docs.google.com/feeds/default/private/full/folder" + folderResourceId + "/contents"; 
Feed<Document> feed = request.GetEverything(); 

foreach (Document entry in feed.Entries) 
{ 
    if (entry.Title == fileName) 
    { 
     var fI = new FileInfo(uploadpath + entry.Title); 
     Stream stream = request.Download(entry, ""); 
     arr = Read(stream); 
     stream.Close(); 
     break; 
    } 
} 

private Byte[] Read(Stream stream) 
{ 
    //long originalPosition = stream.Position; 
    //stream.Position = 0; 

    try 
    { 
     Byte[] readBuffer = new Byte[4096]; 

     int totalBytesRead = 0; 
     int bytesRead; 

     while ((bytesRead = stream.Read(readBuffer, totalBytesRead, readBuffer.Length - totalBytesRead)) > 0) 
     { 
      totalBytesRead += bytesRead; 

      if (totalBytesRead == readBuffer.Length) 
      { 
       int nextByte = stream.ReadByte(); 
       if (nextByte != -1) 
       { 
        Byte[] temp = new Byte[readBuffer.Length * 2]; 
        Buffer.BlockCopy(readBuffer, 0, temp, 0, readBuffer.Length); 
        Buffer.SetByte(temp, totalBytesRead, (Byte)nextByte); 
        readBuffer = temp; 
        totalBytesRead++; 
       } 
      } 
     } 

     Byte[] buffer = readBuffer; 
     if (readBuffer.Length != totalBytesRead) 
     { 
      buffer = new Byte[totalBytesRead]; 
      Buffer.BlockCopy(readBuffer, 0, buffer, 0, totalBytesRead); 
     } 
     return buffer; 
    } 
    finally 
    { 
     //stream.Position = originalPosition; 
    } 
} 

下載後文件保存到本地系統,並顯示使用asp.net

相關問題