Пример #1
0
        private void UploadFiles(string FileName_)
        {
            Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog();
            bool Find = (bool)openFileDialog.ShowDialog();

            FileName_ = GetFileUpload;

            if (Find is true)
            {
                GetFileUpload = openFileDialog.FileName;
            }
            FileStream fileStream = new FileStream(GetFileUpload, FileMode.Open);

            GoogleDrive googleDrive = Auth_Setup();

            if (googleDrive.Exists("/NewFile.pdf") is true)
            {
                MessageBox.Show("This file exisit and is going to be replaced!");
                googleDrive.Upload("/NewFile.pdf", fileStream, 1024, true);
                Username = googleDrive.GetUserName();
            }
            else if (googleDrive.Exists("/NewFile.pdf") is false)
            {
                MessageBox.Show("The new file has been created!");
                googleDrive.Upload("/NewFile.pdf", fileStream, 1024, true);
                Username = googleDrive.GetUserName();
            }

            SpaceAllocation spaceAllocation = googleDrive.GetAllocation();

            string[] Sizes          = { "B", "KB", "MB", "GB", "TB" };
            long     UserAllocation = spaceAllocation.GetTotal();
            int      Order          = 0;

            while (UserAllocation >= 1024 && Order < Sizes.Length - 1)
            {
                Order++;
                UserAllocation = UserAllocation / 1024;
            }

            string Result = string.Format("{0:0.##} {1}", UserAllocation, Sizes[Order]);

            MessageBox.Show("Size available on this account is " + Result);
        }