判断文件是否正在使用

Posted on 2019-01-05 22:03  努力成长静待花开  阅读(201)  评论(0编辑  收藏  举报

实现效果:

  

知识运用:

  File类的move方法  判断是否可以移动

实现代码:

        private void button1_Click(object sender, EventArgs e)
        {
            radioButton2.Checked = true;
            openFileDialog1.ShowDialog();
            try
            {
                File.Move(openFileDialog1.FileName,"C:\\C.EXE");
            }
            catch (Exception ex)
            {
                radioButton1.Checked = true;    
            }
        }