Example #1
0
        private void ViewFile(AmazonS3FileObject file)
        {
            string downloadLocation = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache), file.Filename);

            try
            {
                _amazon.DownloadFile(file.FileObject.Key, downloadLocation);
            }
            catch (Exception ex)
            {
                MessageBox.Show(Window.GetWindow(this), "There was an error downloading the file: " + ex.Message.ToString(), "Error");
                return;
            }


            bool    askToSave = true;
            Process p         = new Process();

            p.StartInfo.FileName = downloadLocation;
            p.Start();
            try
            {
                p.WaitForExit();
            }
            catch (Exception ex) { askToSave = false; }

            if (askToSave)
            {
                if (MessageBox.Show(Window.GetWindow(this), "Do you want to reupload this file?", "Upload change?", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    _amazon.UploadFile(file.FileObject.Key, downloadLocation);
                    GetBucketContents(FolderTree.SelectedItem);
                }
            }
        }
Example #2
0
        private void RenameFile(AmazonS3FileObject file)
        {
            string newName = GetInputString("Rename", file.Filename);

            if (newName == null)
            {
                return;
            }
            string newPath = newName;

            if (file.FileObject.Key.Contains('/'))
            {
                newPath = file.FileObject.Key.Substring(0, file.FileObject.Key.Length - file.Filename.Length) + newName;
            }

            if (IsValidName(newPath, true) == false)
            {
                return;
            }

            if (MessageBox.Show(Window.GetWindow(this), "Are you sure you want to rename this file?",
                                "Rename file?", MessageBoxButton.YesNoCancel, MessageBoxImage.Question) != MessageBoxResult.Yes)
            {
                return;
            }

            _amazon.CopyFile(file.FileObject.Key, newPath);
            _amazon.DeleteFile(file.FileObject.Key);

            GetBucketContents(FolderTree.SelectedItem);
        }