file move c#error“进程无法访问该文件,因为它正由另一个进程使用”

时间:2014-01-02 10:01:46

标签: c# ios file

我已经搜索并阅读了有关此问题的所有问题,但我还没有得到解决方案。我试图将图像移动到目标路径。这是我的代码:

   private void pictureBox6_Click(object sender, EventArgs e)
   {
       string TempDir = "";
       ParentFolder = ParentFolder.TrimEnd(Path.DirectorySeparatorChar);
       for(int i=1 ;i<=ClusterNumber;i++)
       {
           TempDir=ParentFolder+Path.DirectorySeparatorChar+i.ToString();
           bool isExists = System.IO.Directory.Exists(TempDir);
           if (!isExists)
               System.IO.Directory.CreateDirectory(TempDir);
           else
           {
               //DialogResult result = MessageBox.Show("Folder "+i.ToString() +" >already existed in parent folder, do you want to overwrite it ?", >"Confirmation",MessageBoxButtons.YesNo);
           }
       }
       for (int i = 0; i < listBox1.Items.Count; i++)
       {
           TempDir = ParentFolder + Path.DirectorySeparatorChar + listBox2.Items[i].ToString() + Path.DirectorySeparatorChar+ Path.GetFileName(listBox1.Items[i].ToString());
           System.IO.File.Move(listBox1.Items[i].ToString(), TempDir); //The error is here
       }
   }

错误发生在“System.IO.File.Move”上 调试数据:

  TempDir = "C:\\Users\\Chun\\Desktop\\1\\Button.jpg";
  listBox1.Items[i] = "D:\\Revisi TA\\kumpulan gambar\\Button.jpg";
  ParentFolder = "C:\\Users\\Chun\\Desktop";
  listBox2.Items[i] = "1";

0 个答案:

没有答案