45 lines
1.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LibraryUtils.FileChooser
{
public class FileChooser
{
private static string GetFileExtension(DocType type)
{
switch (type)
{
case DocType.Excel:
return ".xlsx";
case DocType.Word:
return ".docx";
case DocType.Pdf:
return ".pdf";
default:
return "";
}
}
public static string GetFileFullName(DocType type)
{
string extension = GetFileExtension(type);
if (string.IsNullOrEmpty(extension))
{
throw new Exception("Invalid file extension");
}
using SaveFileDialog fileDialog = new SaveFileDialog
{
Filter = $"Файлы|*{extension}"
};
if (fileDialog.ShowDialog() == DialogResult.OK)
{
return fileDialog.FileName;
}
return "";
}
}
}