ASP.NET - how to show filesystem with delete option in gridview asp.net

Asked By mani on 06-Feb-12 12:42 AM
hi..i have folder with name  called 'flashfile'

and i will have so many subfolders in this..and how can i show this sub folders from flashfile to  gridview with delete option ??
and i have to show all folders to users..and delete option only for admin also??
any help????
dipa ahuja replied to mani on 06-Feb-12 02:23 AM


<
ItemTemplate>

 <asp:Label ID="lblFile" runat="server" Text='<%# Eval("Filename") %>'></asp:Label>

 <asp:LinkButton ID="linkButton1" CommandName="Delete" runat="server" Text="Delete" />

</ItemTemplate>

 

and Implement the RowCommand Event:

 

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)

{

  if (e.CommandName == "Delete")

  {

  /* DELETE FROM DATABASE */

 

  GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);

  string fileName = ((Label)row.FindControl("lblFile")).Text;

  // Code to fire Delete with query "DELETE from table1 where url=fileName

 

  /* DELETE FROM DIRECTORY */

 

  string path = Server.MapPath("~/Docs/") + fileName;

 

  System.IO.Directory.Delete(path, true);

  }

}