Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static System.IO.Stream DownloadFile(
- IAuthenticator authenticator, Google.Apis.Drive.v2.Data.File file)
- {
- if (!String.IsNullOrEmpty(file.DownloadUrl))
- {
- try
- {
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(file.DownloadUrl));
- authenticator.ApplyAuthenticationToRequest(request);
- HttpWebResponse response = (HttpWebResponse)request.GetResponse();
- if (response.StatusCode == HttpStatusCode.OK)
- {
- return response.GetResponseStream();
- }
- else
- {
- Console.WriteLine(
- "An error occurred: " + response.StatusDescription);
- return null;
- }
- }
- catch (Exception e)
- {
- Console.WriteLine("An error occurred: " + e.Message);
- return null;
- }
- }
- else
- {
- // The file doesn't have any content stored on Drive.
- return null;
- }
- }
Add Comment
Please, Sign In to add comment