如何删除目录文件夹中的文件 [英] how to delete file in Directory folder

查看:110
本文介绍了如何删除目录文件夹中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想删除目录文件夹中的文件。现在我使用datagridview那时我的文件删除文件在datagridview中。那个时候所有文件都删除了目录文件夹.i想要只选择文件可以从目录文件夹中删除。所以PLZ帮帮我。

i want to delete file in directory folder. now i using datagridview that time my file delete file in datagridview .and that time all file deleted in directory folder .i want to only selected file can be deleted from directory folder. so plz help me .

推荐答案

你在datagridview上工作所以你需要一些gridview行删除概念你使用列名如项目模板



只需按照rowdelete事件自动删除目录文件夹中的网格视图



you work on datagridview so you need some gridview row delete concept your using column names like item template

just follow the rowdelete event and automatically delete the grid view in directory folder

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
     dt.Rows.RemoveAt(e.RowIndex); 
    GridView1.DataSource = dt;
    GridView1.DataBind();
}


读一读这个



system.io.file.delete [ ^ ]



您还必须确保您的应用程序或网站用户可以访问您要从中删除文件的文件夹。
Have a read of this

system.io.file.delete[^]

you will also have to make sure that your application or the website user has access to the folder that you want to delete the file from.


如果您正在使用datagridview,则选中复选框值为true或false的复选项的复选框

提供下面的一些代码可以帮助您批次



If you are using datagridview then put checkbox for select items where checkbox value on true or false
Providing some code below which will help you lot

foreach (DataGridViewRow item in dgList.Rows)
{
if (((DataGridViewCheckBoxCell)item.Cells["chkBodyup"]).Value != null)
   if (((DataGridViewCheckBoxCell)item.Cells["chkBodyup"]).Value.ToString().ToUpper() == "TRUE")
       {
       string filepth = item.Cells[6].Value.ToString();
       FileInfo fl = new FileInfo(path);
       fl.Delete();
      }

  }


这篇关于如何删除目录文件夹中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆