C#winForm程序开发,以对话窗口的形式选择文件夹路径。

        /// <summary>
        /// 对话框形式选择文件夹路径
        /// </summary>
        /// <returns>返回所选择的文件夹路径</returns>
        public string ChooseFolderPath()
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            fbd.RootFolder = System.Environment.SpecialFolder.Desktop;
            fbd.ShowNewFolderButton = true;
            fbd.Description = "请选择目录";
            if (fbd.ShowDialog() == DialogResult.OK)
            {
                return fbd.SelectedPath.ToString();
            }
            else
            {
                return "";
            }
        }

C#winForm程序开发,以对话窗口的形式选择Excel文件路径。  

        /// <summary>
        /// 对话框形式选择Excel文件路径
        /// </summary>
        /// <returns>返回所选择的Excel文件路径</returns>
        private string ChooseExcelFilePath()
        {
            OpenFileDialog opd = new OpenFileDialog();
            opd.Filter = @"Excel文件 (*.xls,*.xlsx,*.xlsm)
                |*.xls;*.xlsx;*.xlsm";
            opd.FilterIndex = 1;
            opd.RestoreDirectory = true;
            if (opd.ShowDialog() == DialogResult.OK)
            {
                return opd.FileName;
            }
            else
            {
                return "";
            }
        }
引用:

            string path;
            if ((path =ChooseExcelFilePath())=="")
            {
                //do nothing
            }
            else
            {
                textBox1.Text = path;
            }



相关文章:

  • 2022-12-23
  • 2021-12-10
  • 2022-12-23
  • 2022-01-20
  • 2022-12-23
  • 2022-12-23
  • 2022-01-03
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-22
  • 2021-09-03
  • 2021-12-25
  • 2022-12-23
相关资源
相似解决方案