public static string createFolder(DriveService _service, string _title, string _parent, int id)
        {
            Google.Apis.Drive.v3.Data.File NewDirectory = null;

            // Create metaData for a new Directory
            Google.Apis.Drive.v3.Data.File body = new Google.Apis.Drive.v3.Data.File();
            body.Name        = _title;
            body.Description = "";
            body.MimeType    = "application/vnd.google-apps.folder";
            //body.Parents = "root";
            if (!string.IsNullOrEmpty(_parent))
            {
                body.Parents = new List <string>()
                {
                    _parent
                };
            }
            ;

            //create parent folder for app
            try
            {
                FilesResource.CreateRequest request = _service.Files.Create(body);
                NewDirectory = request.Execute();
            }
            catch (Exception e)
            {
                Console.WriteLine("An error occurred: " + e.Message);
            }


            return(NewDirectory.Id);
        }
Ejemplo n.º 2
0
        public static File createDirectory(DriveService _service, string _title, string _description, string _parent)
        {
            var  watchi       = System.Diagnostics.Stopwatch.StartNew();
            File NewDirectory = null;

            File body = new File();

            body.Name        = _title;
            body.Description = _description;
            body.MimeType    = "application/vnd.google-apps.folder";
            body.Parents     = new List <string>()
            {
                _parent
            };
            try
            {
                FilesResource.CreateRequest request = _service.Files.Create(body);
                NewDirectory = request.Execute();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Error Occured1");
            }
            watchi.Stop();
            var elapsedMs = watchi.ElapsedMilliseconds;

            Console.WriteLine("time create dir = " + elapsedMs / 1000 + " sec " + elapsedMs % 1000 + "msec");
            return(NewDirectory);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create a new Directory.
        /// Documentation: https://developers.google.com/drive/v2/reference/files/insert
        /// </summary>
        /// <param name="service">a Valid authenticated DriveService</param>
        /// <param name="title">The title of the file. Used to identify file or folder name.</param>
        /// <param name="description">A short description of the file.</param>
        /// <param name="parent"></param>
        /// <returns>
        /// Collection of parent folders which contain this file.
        /// Setting this field will put the file in all of the provided folders. root folder.
        /// </returns>
        public static File CreateDirectory(DriveService service, string title, string description, string parent = "root")
        {
            File NewDirectory = null;

            // Create metaData for a new Directory
            File body = new File();

            body.Name        = title;
            body.Description = description;
            body.MimeType    = "application/vnd.google-apps.folder";
            body.Parents     = new List <string>()
            {
                parent
            };

            try
            {
                FilesResource.CreateRequest request = service.Files.Create(body);
                NewDirectory = request.Execute();
            }
            catch (Exception e)
            {
                Console.WriteLine("An error occurred: " + e.Message);
            }

            return(NewDirectory);
        }
Ejemplo n.º 4
0
            public AttemptResult CreateFolder(string folder_name, string parent_id, out string id)
            {
                FilesResource.CreateRequest request = drive_service.Files.Create(
                    new Google.Apis.Drive.v3.Data.File()
                {
                    Name     = folder_name,
                    MimeType = FOLDER_MIME_TYPE,
                    Parents  = new string[] { parent_id }
                }
                    );

                request.Fields = "id";

                try
                {
                    id = request.Execute().Id;
                }
                catch (Google.GoogleApiException)
                {
                    id = null;
                    return(AttemptResult.Failed);
                }

                return(AttemptResult.Succeeded);
            }
Ejemplo n.º 5
0
        private File CreateDirectory(string name, string description, string parent)
        {
            File NewDirectory = null;

            logger.LogInformation($"New google drive directory creation ({name})");
            // Create metaData for a new Directory
            File file = new File()
            {
                Name        = name,
                Description = description,
                MimeType    = "application/vnd.google-apps.folder"
            };

            try
            {
                FilesResource.CreateRequest request = Connector.Service.Files.Create(file);
                NewDirectory = request.Execute();
            }
            catch (Exception e)
            {
                logger.LogError("An error occurred: " + e.Message);
            }

            return(NewDirectory);
        }
Ejemplo n.º 6
0
        public static File createDirectory(DriveService _service, string _name, string _description, string _parent)
        {
            File NewDirectory = null;

            // Create metaData for a new Directory
            var fileMetadata = new File()
            {
                Name = _name,
                //   Parents = new List<string>() { _parent },
                MimeType = "application/vnd.google-apps.folder",
                // Description = _description
            };

            try
            {
                FilesResource.CreateRequest request = _service.Files.Create(fileMetadata);
                request.Fields = "id";
                NewDirectory   = request.Execute();
            }
            catch (Exception e)
            {
                Console.WriteLine("An error occurred: " + e.Message);
            }

            return(NewDirectory);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Create folder method.
        /// </summary>
        /// <param name="parent">The parent of the folder.</param>
        /// <param name="folderName">The folder name.</param>
        /// <returns>A file object of the folder.</returns>
        public Google.Apis.Drive.v3.Data.File CreateFolder(
            string parent, string folderName)
        {
            Google.Apis.Drive.v3.Data.File fileMetadata = new ();

            fileMetadata.Name     = folderName;
            fileMetadata.MimeType = "application/vnd.google-apps.folder";

            IList <string> parents = new List <string>();

            parents.Add(parent);
            fileMetadata.Parents = parents;

            FilesResource.CreateRequest request =
                driveService.Files.Create(fileMetadata);
            request.Fields = "id, name, parents";
            Google.Apis.Drive.v3.Data.File file = request.Execute();

            string message = "Folder ID: " + file.Id;

            Log.Info(CultureInfo.InvariantCulture, m => m(
                         message));

            return(file);
        }
        // DriveService _service: Valid, authenticated Drive service
        // string_ title: Title of the folder
        // string _description: Description of the folder
        // _parent: ID of the parent directory to which the folder should be created

        public static File CreateDirectory(DriveService _service, string _foldername, string _folderdescription, string _parent)
        {
            File NewDirectory = null;

            try
            {
                File body = new File
                {
                    Name        = _foldername,
                    Description = _folderdescription,
                    MimeType    = "application/vnd.google-apps.folder",
                    Permissions = new List <Permission>(),
                    //body.Permissions = new List<Permission> { new Permission(). };
                    //Parent folder or pass 'root' to create on root
                    Parents = new List <string>()
                    {
                        _parent
                    }
                };
                FilesResource.CreateRequest request = _service.Files.Create(body);
                NewDirectory = request.Execute();
                InsertPermission(_service, NewDirectory);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(NewDirectory);
        }
        private string CreateFolder(GDriveFile objGDriveFile)
        {
            string newFileId = null;

            Google.Apis.Drive.v3.Data.File newDirectory = null;

            // Create metaData for a new Directory
            Google.Apis.Drive.v3.Data.File body = new Google.Apis.Drive.v3.Data.File
            {
                Name        = objGDriveFile.Title,
                Description = objGDriveFile.Description,
                MimeType    = objGDriveFile.MimeType,
                Parents     = new List <string>()
                {
                    objGDriveFile.Parent
                },
            };

            using (DriveService service = this.AuthenticateServiceAccount())
            {
                FilesResource.CreateRequest request = service.Files.Create(body);
                request.Fields = "*";
                newDirectory   = request.Execute();
                newFileId      = newDirectory.Id;
            }

            return(newFileId);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Creates a folder
        /// </summary>
        /// <param name="_title">name to create it</param>
        /// <param name="_description">description</param>
        /// <param name="_parent">parent id, empty for root</param>
        /// <returns></returns>
        public static Google.Apis.Drive.v3.Data.File createDirectory(DriveService service, string _title, string _parentID)
        {
            Google.Apis.Drive.v3.Data.File NewDirectory = null;

            // Create metaData for a new Directory
            Google.Apis.Drive.v3.Data.File body = new Google.Apis.Drive.v3.Data.File();
            body.Name        = _title;
            body.Description = "";
            body.MimeType    = "application/vnd.google-apps.folder";
            List <string> parents = new List <string>();

            if (!_parentID.Equals(string.Empty))
            {
                parents.Add(_parentID);
            }
            body.Parents = parents;
            try
            {
                FilesResource.CreateRequest request = service.Files.Create(body);
                NewDirectory = request.Execute();
            }
            catch (Exception e)
            {
                Console.WriteLine("An error occurred: " + e.Message);
            }

            return(NewDirectory);
        }
Ejemplo n.º 11
0
        public static string CreateFolder(string folderName)
        {
            try
            {
                UserCredential credential = GetCredentials();
                DriveService   service    = new DriveService(new BaseClientService.Initializer
                {
                    HttpClientInitializer = credential,
                    ApplicationName       = WebConfigurationManager.AppSettings["GoogleDriveApplicationName"]
                });

                Google.Apis.Drive.v3.Data.File fileMetaData = new Google.Apis.Drive.v3.Data.File
                {
                    Name     = folderName,
                    MimeType = "application/vnd.google-apps.folder"
                };

                FilesResource.CreateRequest request = service.Files.Create(fileMetaData);
                request.Fields = "id";
                Google.Apis.Drive.v3.Data.File file = request.Execute();
                return(file.Id);
            }
            catch (Exception exception)
            {
                LogException(exception, new Dictionary <string, string>(), ErrorSource.ServiceHelper);
                return(String.Empty);
            }
        }
 /// <summary>
 /// Create a new Directory file on Google Drive: GoogleDriveService.Files.Create(metaData)
 /// </summary>
 /// a Valid authenticated DriveService
 /// The title of the file. Used to identify file or folder name.
 /// A short description of the file.
 /// Collection of parent folders which contain this file.
 /// Setting this field will put the file in all of the provided folders. root folder.
 /// Documentation: https://developers.google.com/drive/v3/reference/files/create
 public GoogleDriveManagerResult CreateFolder(DriveService service, string dirName, string description, string parent)
 {
     result = new GoogleDriveManagerResult();
     try
     {
         Google.Apis.Drive.v3.Data.File folder   = null;
         Google.Apis.Drive.v3.Data.File metaData = new Google.Apis.Drive.v3.Data.File()
         {
             Name        = dirName,
             Description = description,
             MimeType    = GoogleDriveMimeService.FolderMimeType
         };
         FilesResource.CreateRequest request = service.Files.Create(metaData);
         folder = request.Execute();
         if (folder != null)
         {
             result.GoogleDriveFileId = folder.Id;
         }
         else
         {
             result.Errors.Add(GoogleDriveManagementConstants.FolderNotCreated);
         }
         return(result);
     }
     catch (Exception e)
     {
         WriteToConsole(GoogleDriveManagementConstants.FolderNotCreatedException + e.Message);
         result.Exceptions.Add(e);
         return(result);
     }
 }
Ejemplo n.º 13
0
 public async Task <Google.Apis.Drive.v3.Data.File> CreateFolderAsync(string folderName)
 {
     Google.Apis.Drive.v3.Data.File file = new Google.Apis.Drive.v3.Data.File();
     file.Name     = folderName;
     file.MimeType = "application/vnd.google-apps.folder";
     FilesResource.CreateRequest request = _service.Files.Create(file);
     request.Fields = "id";
     return(await request.ExecuteAsync());
 }
        public string createDirectory()
        {
            UserCredential credential;

            using (var stream =
                       new FileStream(Server.MapPath("~/Documents/credentials.json"), FileMode.Open, FileAccess.ReadWrite))
            {
                // The file token.json stores the user's access and refresh tokens, and is created
                // automatically when the authorization flow completes for the first time.
                string credPath = Server.MapPath(@"~\Documents\token.json");
                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "admin",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }

            // Create Drive API service.
            var service = new DriveService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });
            string _parent = "AppFolder";

            // Create metaData for a new Directory
            Google.Apis.Drive.v3.Data.File body = new Google.Apis.Drive.v3.Data.File();
            body.Name        = "eOffice";
            body.Description = "";
            body.MimeType    = "application/vnd.google-apps.folder";
            //body.Parents =  new List<string>() { "root" };
            if (!string.IsNullOrEmpty(_parent))
            {
                body.Parents = new List <string>()
                {
                    "root"
                };
            }
            ;
            //create parent folder for app
            //   public static DriveService serv2 = new DriveService();
            try
            {
                //Google.Apis.Drive.v3.FilesResource.ListRequest checkDirectory = _service.Files.List();
                FilesResource.CreateRequest    request      = service.Files.Create(body);
                Google.Apis.Drive.v3.Data.File NewDirectory = request.Execute();
                return(NewDirectory.Id);
            }
            catch (Exception e)
            {
                Console.WriteLine("An error occurred: " + e.Message);
                return("");
            }
        }
        public void CreateApplicationFolder()
        {
            var fileMetadata = new File {
                Name = SpotbaseFolder, MimeType = "application/vnd.google-apps.folder"
            };

            FilesResource.CreateRequest request = _driveService.Files.Create(fileMetadata);
            request.Fields = "id";
            request.Execute();
        }
Ejemplo n.º 16
0
        // https://developers.google.com/drive/api/v3/folder
        private string CreateFolder(string parentId, string name)
        {
            Google.Apis.Drive.v3.Data.File folderToCreate = new Google.Apis.Drive.v3.Data.File();
            folderToCreate.MimeType = Constants.GOOGLE_DRIVE_MIMETYPE_FOLDER;
            folderToCreate.Name     = name;

            FilesResource.CreateRequest request = Service.Files.Create(folderToCreate);
            request.Fields = "id";
            Google.Apis.Drive.v3.Data.File created = request.Execute();

            return(created.Id);
        }
Ejemplo n.º 17
0
        public static async Task <IUploadProgress> UploadFile(string uploadFile, Dictionary <string, string> appFileAttributes = null)
        {
            IsUploadingFile = true;
            DriveService    service  = GetGDriveService();
            IUploadProgress progress = null;

            //Task<IUploadProgress> progress = null;
            if (System.IO.File.Exists(uploadFile))
            {
                File body = new File();
                body.Name        = Path.GetFileName(uploadFile);
                _uploadFilename  = body.Name;
                body.Description = FileUploadDescription;
                body.Properties  = appFileAttributes;
                body.MimeType    = GetMimeType(uploadFile);
                //body.Id = DateTime.Now.ToString("dd-HH:mm:ss.fffff");


                try
                {
                    // File's content.
                    byte[]       byteArray = System.IO.File.ReadAllBytes(uploadFile);
                    MemoryStream stream    = new MemoryStream(byteArray);

                    //FilesResource.UpdateMediaUpload uploadRequest = service.Files.Update(f, "", stream, body.MimeType);
                    FilesResource.CreateRequest cr = service.Files.Create(body);
                    File f = cr.Execute();
                    //FilesResource.CreateMediaUpload uploadRequest = service.Files.Create(f, stream, body.MimeType);
                    //uploadRequest.Body.Id = DateTime.Now.ToString("dd-HH:mm:ss.fffff");
                    //body.Id = "WRJskjslkdjslj3q9";
                    FilesResource.CreateMediaUpload uploadRequest = service.Files.Create(body, stream, body.MimeType);
                    //FilesResource.CreateMediaUpload ur = new FilesResource.CreateMediaUpload(service, body, stream, body.MimeType);
                    //uploadRequest.Fields = "Id";
                    //uploadRequest.Body.Properties = new Dictionary<string, string>();
                    //uploadRequest.Body.Properties.Add("sdkjfs", "kdjskjd");
                    uploadRequest.SupportsTeamDrives = true;
                    uploadRequest.ResponseReceived  += UploadRequest_ResponseReceived;
                    uploadRequest.ProgressChanged   += UploadRequest_ProgressChanged;
                    // new Exception("Exception");
                    progress = await uploadRequest.UploadAsync();//.UploadAsync();
                }
                catch (Exception e)
                {
                    Debug.WriteLine("An error occurred: " + e.Message);
                    throw;
                }
                finally { IsUploadingFile = false; }
            }
            service?.Dispose();
            return(progress);// uploadedFile == null ? string.Empty : uploadedFile.Id;
        }
Ejemplo n.º 18
0
        public string CreateGDriveDir(string NameDir)
        {
            var file = new Google.Apis.Drive.v3.Data.File()
            {
                Name     = NameDir,
                MimeType = "application/vnd.google-apps.folder"
            };

            FilesResource.CreateRequest req = Service.Files.Create(file);
            req.Fields = "id";
            file       = req.Execute();

            return(file.Id);
        }
Ejemplo n.º 19
0
        public GoogleDriveFileModel CreateFolder(string folderName, List <string> parents)
        {
            File fileMetadata = new File()
            {
                Name     = folderName,
                MimeType = GoogleDriveFileTypeEnum.Folder.GetDescription()
            };

            fileMetadata.Parents = parents;
            FilesResource.CreateRequest request = this._driveService.Files.Create(fileMetadata);
            File file = request.Execute();

            return(Mapper.MapFileToGoogleDriveFileModel(file));
        }
Ejemplo n.º 20
0
        private static DriveFile CreateFolder(DriveService driveService, string targetFolderId, DriveFile sourceFile, string folderMimeType)
        {
            DriveFile targetFile = new DriveFile
            {
                MimeType = folderMimeType,
                Name     = sourceFile.Name,
                Parents  = new[] { targetFolderId },
            };

            FilesResource.CreateRequest createRequest = driveService.Files.Create(targetFile);
            createRequest.SupportsAllDrives = true;
            targetFile = createRequest.Execute();
            return(targetFile);
        }
        /// <summary>
        ///  Метод для подключения к Google Drive и создания нового Google Sheet
        /// </summary>
        /// <returns></returns>
        public Google.Apis.Drive.v3.Data.File CreateSheet()
        {
            string[] scopes = new string[] { DriveService.Scope.Drive,
                                             DriveService.Scope.DriveFile, };


            var clientId     = ConfigurationManager.AppSettings["clientId"];;
            var clientSecret = ConfigurationManager.AppSettings["clientSecret"];
            // here is where we Request the user to give us access, or use the Refresh Token that was previously stored in %AppData%
            var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets
            {
                ClientId     = clientId,
                ClientSecret = clientSecret
            }, scopes,
                                                                         Environment.UserName, CancellationToken.None, new FileDataStore("MyAppsToken")).Result;
            //Once consent is recieved, your token will be stored locally on the AppData directory, so that next time you wont be prompted for consent.
            DriveService _service = new DriveService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = "MyAppName",
            });
            var _parent      = "1Ha0GYN6r9_KWRVgN0PHOKpduvU83-2FK";//ID of folder if you want to create spreadsheet in specific folder
            var filename     = "helloworld";
            var fileMetadata = new Google.Apis.Drive.v3.Data.File()
            {
                Name     = filename,
                MimeType = "application/vnd.google-apps.spreadsheet",
                //TeamDriveId = teamDriveID, // IF you want to add to specific team drive
            };

            FilesResource.CreateRequest request = _service.Files.Create(fileMetadata);
            request.SupportsTeamDrives = true;
            fileMetadata.Parents       = new List <string> {
                _parent
            };                                                   // Parent folder id or TeamDriveID
            request.Fields = "id";
            System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return(true); };
            var file = request.Execute();

            Console.WriteLine("File ID: " + file.Id);
            Configuration configManager = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            KeyValueConfigurationCollection confCollection = configManager.AppSettings.Settings;

            confCollection["googleId"].Value = file.Id;
            configManager.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection(configManager.AppSettings.SectionInformation.Name);

            return(file);
        }
Ejemplo n.º 22
0
 //--------------------------------------------------------------------------------------------------
 public static async Task <Google.Apis.Drive.v3.Data.File> CreateFolderAsync(string folderName, string parentFolderId, string hexFolderColor = "#000000")
 {
     Google.Apis.Drive.v3.Data.File fileMetadata = new Google.Apis.Drive.v3.Data.File()
     {
         Name     = folderName,
         MimeType = "application/vnd.google-apps.folder",
         Parents  = new List <string> {
             parentFolderId
         },
         FolderColorRgb = hexFolderColor
     };
     FilesResource.CreateRequest request = Service.Files.Create(fileMetadata);
     request.Fields = "id";
     return(await request.ExecuteAsync());
 }
Ejemplo n.º 23
0
 /// <summary>
 /// 建立一個資料夾
 /// </summary>
 /// <param name="_service"></param>
 /// <param name="parentid"></param>
 /// <param name="title"></param>
 /// <param name="description"></param>
 /// <returns></returns>
 public static GData.File CreateFolder(DriveService _service, string parentid, string title, string description = "")
 {
     try
     {
         // setting file
         string     mimeType = "application/vnd.google-apps.folder";
         GData.File body     = GenFileObject(parentid, title, description, mimeType);
         FilesResource.CreateRequest request = _service.Files.Create(body);
         GData.File folder = request.Execute();
         return(folder);
     }
     catch
     {
         throw;
     }
 }
        public static async Task <File> FetchGoogleFile(string fileName)
        {
            File          f        = null;
            FilesResource resource = _service.Files;
            FileList      files    = null;

            try
            {
                FilesResource.ListRequest req = resource.List();
                req.Q = $"name='{_filePrefix + fileName}'";
                files = await req.ExecuteAsync();
            }
            catch (Exception)
            {
                return(null);
            }

            if (files == null)
            {
                return(null);
            }

            if (files.Files.Count <= 0)
            {
                f          = new File();
                f.Name     = _filePrefix + fileName;
                f.MimeType = "application/json";

                try
                {
                    FilesResource.CreateRequest create = resource.Create(f);
                    await create.ExecuteAsync();
                }
                catch (Exception)
                {
                }
            }
            else
            {
                f = files.Files[0];
            }

            await DownloadGoogleFile(f, fileName);

            return(f);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Create a file in the appDataFolder.
        /// </summary>
        /// <param name="name">The name of the new file</param>
        /// <returns>The ID of the new file</returns>
        public async Task <string> CreateFileAsync(string name)
        {
            List <string> parents = new List <string>();

            parents.Add("appDataFolder");
            var file = new Google.Apis.Drive.v3.Data.File()
            {
                Name    = name,
                Parents = parents
            };

            FilesResource.CreateRequest createRequest = service.Files.Create(file);
            createRequest.Fields = "id";
            var responseFile = await createRequest.ExecuteAsync();

            return(responseFile.Id);
        }
        internal string CreateFolder(string name, string parentId)
        {
            var body = new File
            {
                Name     = name,
                MimeType = FolderType,
                Parents  = new List <string> {
                    parentId
                }
            };

            FilesResource.CreateRequest createRequest = _driveService.Files.Create(body);

            File result = createRequest.Execute();

            return(result.Id);
        }
Ejemplo n.º 27
0
        /// Create a new Directory.
        /// Documentation: https://developers.google.com/drive/v2/reference/files/insert
        ///

        /// a Valid authenticated DriveService
        /// The title of the file. Used to identify file or folder name.
        /// A short description of the file.
        /// Collection of parent folders which contain this file.
        ///                       Setting this field will put the file in all of the provided folders. root folder.
        ///
        public static File createDirectory(DriveService _service, string _title, string _description, string _parent)
        {
            File NewDirectory = null;


            // Init the parentId
            string parentId = "root";

            // Get the file id of the parent Folder, in case it is not "root"
            if (_parent.ToUpper() != "ROOT")
            {
                var parentList = GetFilesByName(_service, _parent, NameSearchOperators.Is);
                // it's possible, that folder name was given more than once -> for this time we will handle the
                // request just in case we find a unique folder name, otherwise we are not sure, which folder we found.
                if (parentList.Count() != 1)
                {
                    throw new ArgumentException($"Parent {_parent} not found", "parent");
                }

                parentId = parentList.FirstOrDefault().Id;
            }
            // in case parentId is still null, we will create our new folder in root folder


            // Create metaData for a new Directory
            File body = new File();

            body.Name        = _title;
            body.Description = _description;
            body.MimeType    = "application/vnd.google-apps.folder";
            body.Parents     = new List <string> {
                parentId
            };
            try
            {
                FilesResource.CreateRequest request = _service.Files.Create(body);
                NewDirectory = request.Execute();
            }
            catch (Exception e)
            {
                Console.WriteLine("An error occurred: " + e.Message);
            }

            return(NewDirectory);
        }
Ejemplo n.º 28
0
        public string CreateFolder(string folderName, string parentFolderId)
        {
            var folder = new File()
            {
                Name     = folderName,
                MimeType = "application/vnd.google-apps.folder",
                Parents  = new List <string>()
                {
                    parentFolderId
                }
            };

            FilesResource.CreateRequest request = service.Files.Create(folder);

            var newFolder = request.Execute();

            return(newFolder.Id);
        }
Ejemplo n.º 29
0
        private TryAsync <string> CreateNewFolder(string folderName, string parentFolderId, List <DriveFile> folders)
        {
            if (folders.Any(f => f.Name.ToLower() == folderName.ToLower()))
            {
                return(TryAsync(() => Task.Run(() => folders.First(f => f.Name.ToLower() == folderName.ToLower()).Id)));
            }
            DriveFile newFolder = new() {
                Name     = folderName,
                MimeType = "application/vnd.google-apps.folder",
                Parents  = new[] { parentFolderId }
            };

            FilesResource.CreateRequest command = _service.Files.Create(newFolder);
            return(TryAsync(async() => {
                DriveFile folder = await command.ExecuteAsync();
                return folder.Id;
            }));
        }
        private async Task <string> CreateTaskerDriveDirectory(DriveService service)
        {
            mLogger.LogInformation($"Drive directory {mTaskerDriveDirectory} not found, creating..");

            GoogleData.File directory = new GoogleData.File()
            {
                Name     = mTaskerDriveDirectory,
                MimeType = FolderMimeType,
            };

            FilesResource.CreateRequest createRequest = service.Files.Create(directory);
            createRequest.Fields = "id";

            GoogleData.File resultDirectory = await createRequest.ExecuteAsync().ConfigureAwait(false);

            mLogger.LogInformation($"Done creating drive directory {mTaskerDriveDirectory}");
            return(resultDirectory.Id);
        }