RhSolutions-AddIn/RhSolutions.AddIn/Services/FileDialog.cs
Sergey Chebotar 663dd39de4 Refactoring
2023-04-20 09:39:25 +03:00

46 lines
1.2 KiB
C#

namespace RhSolutions.Services;
public class FileDialog : IFileDialog
{
private readonly Application _application;
public FileDialog(Application application)
{
_application = application;
}
public string GetFile()
{
var dialog = _application.FileDialog[Microsoft.Office.Core.MsoFileDialogType.msoFileDialogFilePicker];
dialog.AllowMultiSelect = false;
dialog.Filters.Add("Файлы Excel", "*.xls; *.xlsx; *.xlsm");
if (dialog.Show() == -1)
{
return dialog.SelectedItems.Item(1);
}
else return string.Empty;
}
public string[] GetFiles()
{
var dialog = _application.FileDialog[Microsoft.Office.Core.MsoFileDialogType.msoFileDialogFilePicker];
dialog.AllowMultiSelect = true;
dialog.Filters.Add("Файлы Excel", "*.xls; *.xlsx; *.xlsm");
if (dialog.Show() == -1)
{
List<string> files = new();
foreach (string file in dialog.SelectedItems)
{
files.Add(file);
}
return files.ToArray();
}
else return Array.Empty<string>();
}
}