/// <summary>
        /// Обновление файла
        /// </summary>
        /// <param name="name">Имя файла</param>
        /// <param name="value">Записываемый поток</param>
        /// <returns></returns>
        public bool FileUpdate(string name, MemoryStream value)
        {
            bool result = false;

            if (credential == null)
            {
                this.Authorize();
            }
            if (credential == null)
            {
                return(result);
            }

            string new_id;

            if (FileCreate(name, value, out new_id))
            {
                IList <Google.Apis.Drive.v3.Data.File> files = GetFileList();
                if (files != null && files.Count > 0)
                {
                    result = true;
                    try
                    {
                        using (var service = new DriveService(new BaseClientService.Initializer()
                        {
                            HttpClientInitializer = credential,
                            ApplicationName = ApplicationName,
                        }))
                        {
                            foreach (var file in files)
                            {
                                if (file.Name == name && file.Id != new_id)
                                {
                                    try
                                    {
                                        Google.Apis.Drive.v3.FilesResource.DeleteRequest request = service.Files.Delete(file.Id);
                                        string res = request.Execute();
                                    }
                                    catch (Exception)
                                    {
                                        continue;
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                        return(result);
                    }
                }
            }
            return(result);
        }
Exemple #2
0
 public static void DeleteFile(string fileId)
 {
     try
     {
         Google.Apis.Drive.v3.DriveService service = GetService_v3();
         Google.Apis.Drive.v3.FilesResource.DeleteRequest DeleteRequest = service.Files.Delete(fileId);
         DeleteRequest.Execute();
     }
     catch (Exception ex)
     {
     }
 }