FileDialog.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System.IO;
  2. namespace System.Windows.Forms
  3. {
  4. public abstract class FileDialog : IDisposable
  5. {
  6. protected internal Microsoft.Win32.FileDialog dialog;
  7. public string Title
  8. {
  9. get => dialog.Title;
  10. set => dialog.Title = value;
  11. }
  12. public string FileName
  13. {
  14. get => dialog.FileName;
  15. set => dialog.FileName = value;
  16. }
  17. public string Filter
  18. {
  19. get => dialog.Filter;
  20. set => dialog.Filter = value;
  21. }
  22. public int FilterIndex
  23. {
  24. get => dialog.FilterIndex;
  25. set => dialog.FilterIndex = value;
  26. }
  27. public string DefaultExt
  28. {
  29. get => dialog.DefaultExt;
  30. set => dialog.DefaultExt = value;
  31. }
  32. public string InitialDirectory
  33. {
  34. get => dialog.InitialDirectory;
  35. set
  36. {
  37. if (!string.IsNullOrEmpty(value))
  38. {
  39. try
  40. {
  41. dialog.InitialDirectory = Path.GetFullPath(value);
  42. }
  43. catch
  44. {
  45. dialog.InitialDirectory = "";
  46. }
  47. }
  48. else
  49. {
  50. dialog.InitialDirectory = value;
  51. }
  52. }
  53. }
  54. public bool CheckFileExists
  55. {
  56. get => dialog.CheckFileExists;
  57. set => dialog.CheckFileExists = value;
  58. }
  59. public bool CheckPathExists
  60. {
  61. get => dialog.CheckPathExists;
  62. set => dialog.CheckPathExists = value;
  63. }
  64. public void Dispose() { }
  65. public DialogResult ShowDialog()
  66. {
  67. return dialog.ShowDialog() == true ? DialogResult.OK : DialogResult.Cancel;
  68. }
  69. }
  70. }