2017-06-02 4 views
0

私はhttps://developers.google.com/drive/v3/web/manage-downloadsを使用していますが、私はアクセス権を持ってGoogleドライブからファイルをダウンロードできるコードの作業コピーを持っています。それが真のDOCファイルは、あなたならGoogleドキュメントの内容を読む方法

private static void DownloadFile(string fileId, DriveService driveService) 
{ 

    var request = driveService.Files.Export(fileId, "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); 
    var stream = new System.IO.MemoryStream(); 
    // Add a handler which will be notified on progress changes. 
    // It will notify on each chunk download and when the 
    // download is completed or failed. 
    request.MediaDownloader.ProgressChanged += 
      (IDownloadProgress progress) => 
      { 
       switch (progress.Status) 
       { 
        case DownloadStatus.Downloading: 
         { 
          Console.WriteLine(progress.BytesDownloaded); 
          break; 
         } 
        case DownloadStatus.Completed: 
         { 
          Console.WriteLine("Download complete."); 
          break; 
         } 
        case DownloadStatus.Failed: 
         { 
          Console.WriteLine("Download failed."); 
          break; 
         } 
       } 
      }; 


    request.Download(stream); 

    using (FileStream file = new FileStream("file.doc", FileMode.Create, FileAccess.Write)) 
    { 
     stream.WriteTo(file); 
    } 
} 

答えて

0

:私はワード文書を読むことができます任意の方法は、ファイルをダウンロードするために

サンプルコード(gdrive-新規作成新しいドキュメントを使用して作成)が

ですあなたメートル

Code7248.word_reader

private string readFileContent(string pDocPath) 
{ 
    if(!System.IO.File.Exists(pDocPath)) 
    { 
     Console.WriteLine("The file doesn't exist"); 
     return String.Empty; 
    } 

    var extractor = new TextExtractor(pDocPath); 
    var txt = extractor.ExtractText(); 
    Console.WriteLine(txt); 
    return txt; 
} 

static void Main(string[] args) 
{  
    var strDocPath = @"C:\Temp\yourWordDoc.doc"; 
    var strDocTxt = readFileContent(strDocPath); 
} 
+0

すぐにお返事いただきありがとうございますが、ドライブから直接ドキュメントをダウンロードしてダウンロードしたいと思います。 – user1621791

0

を使用してテキストを取得することができますAY GoogleドライブUIでopen filesにこれら二つの方法を確認したい:

コンテキストメニュー項目文書に対するユーザーの権限をチェックする

  • コールfiles.getで開き、メタデータやダウンロードをフェッチファイルの内容ファイルがGoogleドキュメントのMIMEタイプで作成されている場合は、Googleドキュメントを開いてサポートされているフォーマットに変換します。

ファイルを開くためのGoogleのピッカーダイアログ

  • アプリケーションは、アプリ自体の中からコンテンツを選択するために、ファイルピッカーを表示することができます。詳細については、files picker guideを参照してください。
関連する問題