Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 .
Posted
Comments
mr.priyank 27-Nov-13 7:19am    
Please explain more with your code.

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

C#
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
     dt.Rows.RemoveAt(e.RowIndex); 
    GridView1.DataSource = dt;
    GridView1.DataBind();
}
 
Share this answer
 
v2
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.
 
Share this answer
 
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();
      }

  }
 
Share this answer
 
use this
--------------

add namespace System.IO

XML
if (File.Exists(Server.MapPath("~") + "/<Yourfoldername>/<yourfilename>"))
     File.Delete(Server.MapPath("~") + "/<Yourfoldername>/<yourfilename>");
 
Share this answer
 
v2
Comments
Suvabrata Roy 27-Nov-13 7:28am    
Is this the answer?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900