protected override void Execute(CodeActivityContext context) { var isSaveAs = IsSaveAs.Get(context); var initialDirectory = InitialDirectory.Get(context); var title = Title.Get(context); var defaultExt = DefaultExt.Get(context); var filter = Filter.Get(context); var filterIndex = FilterIndex.Get(context); var checkFileExists = CheckFileExists.Get(context); var checkPathExists = CheckPathExists.Get(context); var multiselect = Multiselect.Get(context); System.Windows.Forms.FileDialog dialog; if (isSaveAs) { dialog = new System.Windows.Forms.SaveFileDialog(); } else { dialog = new System.Windows.Forms.OpenFileDialog(); ((System.Windows.Forms.OpenFileDialog)dialog).Multiselect = multiselect; } if (!string.IsNullOrEmpty(title)) { dialog.Title = title; } if (!string.IsNullOrEmpty(defaultExt)) { dialog.DefaultExt = defaultExt; } if (!string.IsNullOrEmpty(filter)) { dialog.Filter = filter; dialog.FilterIndex = filterIndex; } dialog.CheckFileExists = checkFileExists; dialog.CheckPathExists = checkPathExists; System.Windows.Forms.DialogResult result = System.Windows.Forms.DialogResult.Cancel; GenericTools.RunUI(() => { result = dialog.ShowDialog(); }); if (result != System.Windows.Forms.DialogResult.OK) { context.SetValue(FileName, null); context.SetValue(FileNames, null); return; } context.SetValue(FileName, dialog.FileName); context.SetValue(FileNames, dialog.FileNames); }
protected override void Execute(CodeActivityContext context) { var isSaveAs = IsSaveAs.Get(context); var initialDirectory = InitialDirectory.Get(context); var title = Title.Get(context); var defaultExt = DefaultExt.Get(context); var filter = Filter.Get(context); var filterIndex = FilterIndex.Get(context); var checkFileExists = CheckFileExists.Get(context); var checkPathExists = CheckPathExists.Get(context); var multiselect = Multiselect.Get(context); System.Windows.Forms.FileDialog dialog; if (isSaveAs) { dialog = new System.Windows.Forms.SaveFileDialog(); } else { dialog = new System.Windows.Forms.OpenFileDialog(); ((System.Windows.Forms.OpenFileDialog)dialog).Multiselect = multiselect; } if (!string.IsNullOrEmpty(title)) { dialog.Title = title; } if (!string.IsNullOrEmpty(defaultExt)) { dialog.DefaultExt = defaultExt; } if (!string.IsNullOrEmpty(filter)) { dialog.Filter = filter; dialog.FilterIndex = filterIndex; } try { if (!string.IsNullOrEmpty(initialDirectory) && !initialDirectory.Contains("\\")) { Enum.TryParse(initialDirectory, out Environment.SpecialFolder specialfolder); initialDirectory = Environment.GetFolderPath(specialfolder); } } catch (Exception) { throw; } if (!string.IsNullOrEmpty(initialDirectory)) { dialog.InitialDirectory = initialDirectory; } dialog.CheckFileExists = checkFileExists; dialog.CheckPathExists = checkPathExists; System.Windows.Forms.DialogResult result = System.Windows.Forms.DialogResult.Cancel; GenericTools.RunUI(() => { result = dialog.ShowDialog(); }); if (result != System.Windows.Forms.DialogResult.OK) { context.SetValue(FileName, null); context.SetValue(FileNames, null); return; } context.SetValue(FileName, dialog.FileName); context.SetValue(FileNames, dialog.FileNames); }