Untitled

 avatar
unknown
plain_text
2 years ago
1.7 kB
12
Indexable
private async void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            string sourceFilePath = Path.GetFileName(PickAFileOutputTextBlock.Text.Trim());
            string destinationFolderPath = Path.Combine(InputFilePath.Text.Trim());
            var folderPicker = new FolderPicker();
            folderPicker.SuggestedStartLocation = PickerLocationId.Desktop;
            folderPicker.FileTypeFilter.Add("*");
            var pickedFolder = await folderPicker.PickSingleFolderAsync();

            if (string.IsNullOrEmpty(sourceFilePath) || string.IsNullOrEmpty(destinationFolderPath))
            {
                SaveButton.IsEnabled = false; // Установка свойства IsEnabled в значение False
            }
            else
            {
                SaveButton.IsEnabled = true;
                // Перенос файлов
                try
                {
                    StorageFile sourceFile = await StorageFile.GetFileFromPathAsync(sourceFilePath);
                    StorageFolder destinationFolder = await StorageFolder.GetFolderFromPathAsync(destinationFolderPath);
                    string destinationPath = Path.Combine(destinationFolderPath, Path.GetFileName(sourceFilePath));

                    await sourceFile.MoveAsync(destinationFolder, destinationPath, NameCollisionOption.ReplaceExisting);
                }
                catch (Exception ex)
                {
                    // Обработка ошибки при переносе файла
                    Console.WriteLine($"Ошибка при переносе файла: {ex.Message}");
                }
            }
        }
Editor is loading...