小编San*_*ewa的帖子

"尝试删除文件时,进程无法访问该文件,因为它正被另一个进程使用"

当逐个删除文件时,会生成错误,因为"进程无法访问文件",因为在尝试删除文件时,其他进程正在使用该文件

代码:有关删除文件的任何建议吗?

      private void DeleteFilesFromDestination()
      {
           string consolidatedFolder = System.Configuration.ConfigurationManager.AppSettings["path"].ToString();

           foreach (String file in ListBoxDeleteFiles.Items)
           {
                try
                {
                     // delete each selected files from the specified TargetFolder 
                     if (System.IO.File.Exists(consolidatedFolder + @"\" + System.IO.Path.GetFileName(file)))
                     {
                         proc.WaitForExit(); 
                         System.IO.File.Delete(consolidatedFolder + @"\" + System.IO.Path.GetFileName(file));
                     }
                }
                catch (Exception ex)
                {
                     MessageBox.Show("Error Could not Delete file from disk " + ex.Message, "Shipment Instruction",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
                     return;
                }

           }
      }
Run Code Online (Sandbox Code Playgroud)

注意:图像将被加载到这样的flowlayout面板

 //Open the files to see
          private void ListBoxSourceFiles_Click(object sender, EventArgs e)
          {
               try
               {
                    if …
Run Code Online (Sandbox Code Playgroud)

.net c#

2
推荐指数
1
解决办法
6481
查看次数

标签 统计

.net ×1

c# ×1