I am building a document uploader web system using asp.net 4.0 . I am stuck in gridview. I can delete the data from gridview. The data gets deleted in the sql table, but 开发者_Python百科the document, which is stored in my folder remains.
I want the document to get deleted when user clicks delete in gridview..is it possible..have been working days on this..
Thanks in advance.
There is a RowDeleted
event of gridview which is fired after the deletion of a row, you have to write logic in this event. like...
protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
{
if (System.IO.File.Exists("DocumentPath"))
{
System.IO.File.Delete("DocumentPath");
}
}
You can simply call the following line at the end of your GridView's OnRowDeleting event:
if (System.IO.File.Exists("PathToYourDoc")) { System.IO.File.Delete("PathToYourDoc"); }
About how to find a document path, you can visit the following link to see different examples:
http://www.dotnetperls.com/path
精彩评论