Guest User

Untitled

a guest
Jan 18th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  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. }
Add Comment
Please, Sign In to add comment