title: How to download files from google drive and save to a folder on local using C#
body: <p>I need to download files from google drive and save to a folder on local using C#.
  I have done as described in Google Developer API <a href="https://developers.google.com/drive/v3/web/manage-downloads" rel="nofollow noreferrer">documentation</a> but I'm getting the file with an invalid format. Please suggest how to download it.</p>
  
  <p>I done:</p>
  
  <pre><code>downloadUrl = url of the file (eg: https://drive.google.com/uc?id=1ULNeKdDoCRmWgPPBW8-d1EGUZgqvA1Ul&amp;export=download)&lt;br/&gt;
  filename = some name with extension
  
  
  private bool SaveToDir(string downloadUrl,string filename) {
  string filePath = Server.MapPath("imports/");
  bool resp = false;
  DriveService ds = new DriveService();
  Uri temp = new Uri(downloadUrl);
  string fileId = HttpUtility.ParseQueryString(temp.Query).Get("id");
  var req = ds.Files.Get(fileId.Trim());
  var stream = new MemoryStream();
  req.MediaDownloader.ProgressChanged += (Google.Apis.Download.IDownloadProgress dp)=&gt; {
  switch (dp.Status)
  {
   case Google.Apis.Download.DownloadStatus.Downloading:
        Message("downloading, please wait....");
        break;
   case Google.Apis.Download.DownloadStatus.Completed:
        using (FileStream file = new FileStream(filePath, FileMode.Create, FileAccess.Write))
              {
                  stream.WriteTo(file);
                  Message("File Downloaded successfully.");
              }
        resp = true;
        break;
   case Google.Apis.Download.DownloadStatus.Failed:
        Message("Failed to Download.");
        resp = false;
        break;
   }
   };
   req.Download(stream);
  </code></pre>