/// <summary> /// Show Open File dialog /// </summary> /// <param name="importData">Data to import</param> /// <param name="returnFileName">File name will be returned</param> /// <returns>Dialog result</returns> public static DialogResult ShowOpenDialog(ImportData importData, ref String returnFileName) { using (OpenFileDialog importDialog = new OpenFileDialog()) { importDialog.Title = importData.Title; importDialog.InitialDirectory = importData.ImportFolder; importDialog.Filter = importData.Filter; importDialog.RestoreDirectory = true; DialogResult result = importDialog.ShowDialog(); if (result != DialogResult.Cancel) { returnFileName = importDialog.FileName; } return(result); } }
/// <summary> /// Import /// </summary> /// <param name="data"></param> private static DialogResult Import(ImportData data) { String returnFilename = String.Empty; DialogResult result = ShowOpenDialog(data, ref returnFilename); if (result != DialogResult.Cancel) { data.ImportFileFullName = returnFilename; if (!data.Import()) { TaskDialog.Show("Import", "Cannot import " + Path.GetFileName(data.ImportFileFullName) + " in current settings.", TaskDialogCommonButtons.Ok); } } return result; }
/// <summary> /// Show Open File dialog /// </summary> /// <param name="importData">Data to import</param> /// <param name="returnFileName">File name will be returned</param> /// <returns>Dialog result</returns> public static DialogResult ShowOpenDialog(ImportData importData, ref String returnFileName) { using (OpenFileDialog importDialog = new OpenFileDialog()) { importDialog.Title = importData.Title; importDialog.InitialDirectory = importData.ImportFolder; importDialog.Filter = importData.Filter; importDialog.RestoreDirectory = true; DialogResult result = importDialog.ShowDialog(); if (result != DialogResult.Cancel) { returnFileName = importDialog.FileName; } return result; } }
/// <summary> /// Import /// </summary> /// <param name="data"></param> private static DialogResult Import(ImportData data) { String returnFilename = String.Empty; DialogResult result = ShowOpenDialog(data, ref returnFilename); if (result != DialogResult.Cancel) { data.ImportFileFullName = returnFilename; if (!data.Import()) { MessageBox.Show("Cannot import " + Path.GetFileName(data.ImportFileFullName) + " in current settings.", "Import", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } return result; }