private string PreShowDialog() { string strPrevWorkDir = WinUtil.GetWorkingDirectory(); string strNew = Program.Config.Application.GetWorkingDirectory(m_strContext); if (!string.IsNullOrEmpty(m_strInitialDirectoryOvr)) { strNew = m_strInitialDirectoryOvr; } WinUtil.SetWorkingDirectory(strNew); // Always, even when no context try { string strWD = WinUtil.GetWorkingDirectory(); this.FileDialog.InitialDirectory = strWD; } catch (Exception) { Debug.Assert(false); } return(strPrevWorkDir); }
private void PostShowDialog(string strPrevWorkDir, DialogResult dr) { string strCur = null; // Modern file dialogs (on Windows >= Vista) do not change the // working directory (in contrast to Windows <= XP), thus we // derive the working directory from the first file try { if (dr == DialogResult.OK) { string strFile = null; if (m_bSaveMode) { strFile = this.FileDialog.FileName; } else if (this.FileDialog.FileNames.Length > 0) { strFile = this.FileDialog.FileNames[0]; } if (!string.IsNullOrEmpty(strFile)) { strCur = UrlUtil.GetFileDirectory(strFile, false, true); } } } catch (Exception) { Debug.Assert(false); } if (!string.IsNullOrEmpty(strCur)) { Program.Config.Application.SetWorkingDirectory(m_strContext, strCur); } WinUtil.SetWorkingDirectory(strPrevWorkDir); }