簡體   English   中英

C#從Google驅動器下載文檔未正確保存

[英]C# to download document from google drive not saving correctly

我正在編寫一個簡單的程序,以從我的Google驅動器中下載文檔(.docx)並保存為該文檔。 問題在於,保存文件時,Microsoft word無法打開它,因為它說文件已損壞。 如果有人能想到為什么這行不通,我將非常感謝您的幫助,因為我對此感到有些困惑。

編碼:

    Uri link = new Uri(sharablelinkhere);
    DriveService service = new DriveService();
    var stream = service.HttpClient.GetStreamAsync(link);
    var result = stream.Result;
    using (var fileStream = File.Create("E:\\test.docx"))
    {
        result.CopyTo(fileStream);
    }

我找到了答案。 我需要正確的導出鏈接,並且一切正常。

https://docs.google.com/document/d/FILE_ID/export?format=doc

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM