public static void downloadFromDrive(string filename, string fileId, string savePath, string mimeType, frmMain parentForm)
        {
            frmMain parent    = parentForm;
            long    totalSize = 100000;

            parent.updateStatusBar(0, "Downloading...");
            try
            {
                if (Path.HasExtension(filename))
                {
                    var request = driveService.Files.Get(fileId);

                    var stream = new System.IO.MemoryStream();
                    System.Diagnostics.Debug.WriteLine(fileId);
                    // 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:
                        {
                            System.Diagnostics.Debug.WriteLine(progress.BytesDownloaded);

                            parent.updateStatusBar((progress.BytesDownloaded * 100) / totalSize, "Downloading...");
                            break;
                        }

                        case DownloadStatus.Completed:
                        {
                            parent.updateStatusBar(100, "Download complete.");
                            System.Diagnostics.Debug.WriteLine("Download complete.");
                            break;
                        }

                        case DownloadStatus.Failed:
                        {
                            parent.updateStatusBar(0, "Download failed.");
                            System.Diagnostics.Debug.WriteLine("Download failed.");
                            MessageBox.Show("File failed to download!!!", "Download Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            break;
                        }
                        }
                    };
                    request.Download(stream);
                    convertMemoryStreamToFileStream(stream, savePath + @"\" + @filename);
                    stream.Dispose();
                }
                else
                {
                    string extension = "", converter = "";
                    foreach (MimeTypeConvert obj in MimeConverter.mimeList())
                    {
                        if (mimeType == obj.mimeType)
                        {
                            extension = obj.extension;
                            converter = obj.converterType;
                        }
                    }
                    System.Diagnostics.Debug.WriteLine("{0} {1} {2}", fileId, extension, mimeType);
                    var request = driveService.Files.Export(fileId, converter);
                    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:
                        {
                            parent.updateStatusBar(100, "Download Complete!");
                            Console.WriteLine("Download complete.");
                            break;
                        }

                        case DownloadStatus.Failed:
                        {
                            parent.updateStatusBar(0, "Download failed.");
                            Console.WriteLine("Download failed.");
                            MessageBox.Show("File failed to download!!!", "Download Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            break;
                        }
                        }
                    };
                    request.Download(stream);
                    convertMemoryStreamToFileStream(stream, savePath + @"\" + @filename + extension);
                    stream.Dispose();
                }
            }
            catch (Exception exc)
            {
                System.Diagnostics.Debug.WriteLine(exc.Message + " Download From Drive Error");
                Gtools.writeToFile(frmMain.errorLog, Environment.NewLine + DateTime.Now.ToString() +
                                   Environment.NewLine + exc.Message + " Download From Drive.\n");
            }
        }
        private static bool uploadFileToDrive(string folderId, string fileName, string filePath, string fileType, frmMain parentForm)
        {
            frmMain parent = parentForm;

            parent.updateStatusBar(0, "Uploading...");
            long totalSize = 100000;

            try
            {
                FileInfo fi = new FileInfo(filePath);
                totalSize = fi.Length;

                var fileMetadata = new Google.Apis.Drive.v3.Data.File()
                {
                    Name = fileName
                };
                if (folderId != null)
                {
                    fileMetadata.Parents = new List <string>
                    {
                        folderId
                    };
                }
                FilesResource.CreateMediaUpload request;
                using (var stream = new System.IO.FileStream(filePath, System.IO.FileMode.Open))
                {
                    request = driveService.Files.Create(
                        fileMetadata, stream, fileType);
                    request.ChunkSize        = FilesResource.CreateMediaUpload.MinimumChunkSize;
                    request.ProgressChanged += (IUploadProgress progress) =>
                    {
                        switch (progress.Status)
                        {
                        case UploadStatus.Uploading:
                        {
                            parent.updateStatusBar((progress.BytesSent * 100) / totalSize, "Uploading...");
                            System.Diagnostics.Debug.WriteLine(progress.BytesSent);
                            break;
                        }

                        case UploadStatus.Completed:
                        {
                            parent.updateStatusBar(100, "Upload complete.");
                            System.Diagnostics.Debug.WriteLine("Upload complete.");
                            break;
                        }

                        case UploadStatus.Failed:
                        {
                            parent.updateStatusBar(0, "Upload failed.");
                            System.Diagnostics.Debug.WriteLine("Upload failed.");
                            //MessageBox.Show("File failed to upload!!!", "Upload Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            Gtools.writeToFile(frmMain.errorLog, Environment.NewLine + DateTime.Now.ToString() +
                                               Environment.NewLine + "Upload failed.\n");
                            break;
                        }
                        }
                    };
                    request.Fields = "id";
                    request.Upload();
                }
                var file = request.ResponseBody;
                System.Diagnostics.Debug.WriteLine("File ID:{0} \n FileName {1} ", file.Id, file.Name);
                return(true);
            }
            catch (Exception exc)
            {
                System.Diagnostics.Debug.WriteLine(exc.Message + " Upload file to Drive Error");
                Gtools.writeToFile(frmMain.errorLog, Environment.NewLine + DateTime.Now.ToString() +
                                   Environment.NewLine + exc.Message + " Upload file to Drive Error.\n");
                return(false);
            }
        }