daily pastebin goal
41%
SHARE
TWEET

Untitled

a guest Jan 18th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static System.IO.Stream DownloadFile(
  2.      IAuthenticator authenticator, Google.Apis.Drive.v2.Data.File file)
  3.     {
  4.         if (!String.IsNullOrEmpty(file.DownloadUrl))
  5.         {
  6.             try
  7.             {
  8.                 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(file.DownloadUrl));
  9.                 authenticator.ApplyAuthenticationToRequest(request);
  10.                 HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  11.                 if (response.StatusCode == HttpStatusCode.OK)
  12.                 {
  13.                     return response.GetResponseStream();
  14.                 }
  15.                 else
  16.                 {
  17.                     Console.WriteLine(
  18.                         "An error occurred: " + response.StatusDescription);
  19.                     return null;
  20.                 }
  21.             }
  22.             catch (Exception e)
  23.             {
  24.                 Console.WriteLine("An error occurred: " + e.Message);
  25.                 return null;
  26.             }
  27.         }
  28.         else
  29.         {
  30.             // The file doesn't have any content stored on Drive.
  31.             return null;
  32.         }
  33.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top