天天看點

c#檔案對話框

//檔案對話框(選擇檔案)
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.InitialDirectory = "d:\\";
            ofd.DefaultExt = "*.TXT|*.txt";
            ofd.Filter = "*.TXT|*.txt";
            ofd.Multiselect = false;
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string zdbPath = ofd.FileName;
            }           
//檔案夾對話框(選擇檔案夾)
            FolderBrowserDialog pFolder = new FolderBrowserDialog();
            pFolder.ShowNewFolderButton = false;
            pFolder.Description = "請選擇路徑:";
            if (pFolder.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string selectPath = pFolder.SelectedPath;
            }           
//儲存檔案對話框
            SaveFileDialog saveDG = new SaveFileDialog();
            saveDG.Filter = "Excel檔案|*.xls";
            if (saveDG.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string savePath = saveDG.FileName;
            }           
//判斷選擇對話框
            if (MessageBox.Show("是否繼續執行", "系統提示", MessageBoxButtons.OKCancel) != DialogResult.OK)
            { return; }