2011-10-13 86 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

相关问题