ccx527191915
ssr奥利奥
2016-01-25 06:31

c#打开文件夹程序怎么打开windows默认的文件夹

  • c#
 private void pictureBox9_Click(object sender, EventArgs e)
        {
            if (Directory.Exists(".\\Background") == false)
            {
                Directory.CreateDirectory(".\\Background");
                OpenFileDialog of1 = new OpenFileDialog();
                of1.InitialDirectory = "c:\\";
                of1.Filter = "png|*.png|jpg|*.jpg|bmp|*.bmp";
                of1.RestoreDirectory = true;
                of1.FilterIndex = 1;
                if (of1.ShowDialog() == DialogResult.OK)
                {
                    picfile = of1.FileName;
                    picName = of1.SafeFileName;
                    try
                    {
                        File.Copy(picfile, string.Format("Background\\{0}", picName, true));
                    }
                    catch (Exception)
                    {

                        //
                    }
                    this.BackgroundImage = Image.FromFile(string.Format("Background\\{0}", picName));
                }
            }
            else
            {
                OpenFileDialog of = new OpenFileDialog();
                of.InitialDirectory = "c:\\";
                of.Filter = "png|*.png|jpg|*.jpg|bmp|*.bmp";
                of.RestoreDirectory = true;
                of.FilterIndex = 1;
                if (of.ShowDialog() == DialogResult.OK)
                {
                    picfile = of.FileName;
                    picName = of.SafeFileName;
                    try
                    {
                        File.Copy(picfile, string.Format("Background\\{0}", picName, true));
                    }
                    catch (Exception)
                    {

                        //
                    }
                    this.BackgroundImage = Image.FromFile(string.Format("Background\\{0}", picName));
                }
            }

        }

我有这样的一个程序,每次都是打开C盘。我想让他能够记忆我曾经打开的文件夹路径。就像用浏览器保存图片一样,每次右键出来的选择文件件路径都是一样的。

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答