0
我試圖使用FileResource API中的ExportLinks從Google Drive下載工作表。C#從Google Drive下載電子表格
但是,我得到的回覆不是電子表格,而是代表電子表格或類似內容的HTML文件。
這裏是要求我使用:
FilesResource.GetRequest getF = new FilesResource.GetRequest(service, "1y92Rok6oYKMwvc-Oq4Uurah7y552sfmIbyD9Wzmpq54");
Google.Apis.Drive.v2.Data.File f = getF.Execute();
string downloadUrl = f.ExportLinks["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"];
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(downloadUrl));
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
ReadWriteStream(response.GetResponseStream(), File.OpenWrite("D:\\tmp.xlsx"));
我使用存儲流的功能:
static private void ReadWriteStream(Stream readStream, Stream writeStream)
{
int Length = 256;
Byte[] buffer = new Byte[Length];
int bytesRead = readStream.Read(buffer, 0, Length);
// write the required bytes
while (bytesRead > 0)
{
writeStream.Write(buffer, 0, bytesRead);
bytesRead = readStream.Read(buffer, 0, Length);
}
readStream.Close();
writeStream.Close();
}
任何人都可以指出我在做什麼錯?
,完美的工作,感謝您的方法。 – Tim