Ben
Ben

Reputation: 21

unable to delete data using gridview

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 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.

Upvotes: 1

Views: 360

Answers (2)

Muhammad Akhtar
Muhammad Akhtar

Reputation: 52241

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");
    }
}

Upvotes: 3

ncakmak
ncakmak

Reputation: 4044

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

Upvotes: 0

Related Questions