Hi,
I am able to delete the data from database. My Problem is how to delete a file from the folder that is linked to the database using c#, asp.net. Below is my code snippet for your reference. I would greatly appreciate your help/suggestion.
Thank you.

protected void lnkdelete_Click(object sender, EventArgs e)
    {

        LinkButton lnkbtn = sender as LinkButton;
        //getting particular row linkbutton
        GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
        //getting userid of particular row
        int id = Convert.ToInt32(gvrecords.DataKeys[gvrow.RowIndex].Value.ToString());
        string username = gvrow.Cells[0].Text;
        MySqlConn.Open();
        MySqlCommand cmd = new MySqlCommand("delete from file_info where id=" + id, MySqlConn);
        int result = cmd.ExecuteNonQuery();
        MySqlConn.Close();

       // File.Delete(@"E:\uploadfiles\test.txt"); 


        if (result == 1)
        {
            BindFileDetails();
            //Displaying alert message after successfully deletion of user
            ScriptManager.RegisterStartupScript(this, this.GetType(), "alertmessage", "javascript:alert('" + username + "'s files deleted successfully')", true);
        }
    }

what error are you getting when you run this code? Or have you not figured out how to get the file name to delete? If not, you would have to query the database before doing the deletion so you have the name of the file to delete then run the delete query and the file.delete method.

Can anyone here who has knows the java code for the same functionality...

If the file is "in-use", you cannot delete it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.