C# 从数据库中删除包含图像的记录后,从文件夹中删除图像

C# 从数据库中删除包含图像的记录后,从文件夹中删除图像,c#,sql,C#,Sql,我的数据库中有一个表,其中包含两列ID和Image。 将图像插入数据库时,我使用以下代码 <pre lang='cs'> SqlCommand cmd = new SqlCommand("INSERT INTO info(ID,Img_Image) VALUES(@ID,@Img_image)); cmd.Parameters.AddWithValue("@ID", txtID.Text); cmd.Parameters.AddWi

我的数据库中有一个表,其中包含两列ID和Image。 将图像插入数据库时,我使用以下代码

    <pre lang='cs'>

       SqlCommand cmd = new SqlCommand("INSERT INTO info(ID,Img_Image) VALUES(@ID,@Img_image));
       cmd.Parameters.AddWithValue("@ID", txtID.Text);
       cmd.Parameters.AddWithValue("@Image", test_image);
    </pre>

SqlCommand cmd=newsqlcommand(“插入到信息(ID,Img_图像)值(@ID,@Img_图像));
cmd.Parameters.AddWithValue(“@ID”,txtID.Text);
cmd.Parameters.AddWithValue(“@Image”,test\u Image);
。。。 该测试映像从一个路径加载映像,即(C:\foldername)

现在我的问题是,当我删除一个特定的记录时,文件夹中相应的图像应该被删除


注意:我正在使用标准SQL删除代码删除记录。

从表中删除记录后,您可以使用System.IO.file.delete或使用FileInfo删除物理文件

string filePath = "C:\test.txt";
FileInfo file = new FileInfo(filePath);
if (file.Exists)
{
   file.Delete();
}

删除您的物理文件-工作100%

File.Delete(Server.MapPath("../App_Themes/UPLOADS/banner_img/5.jpg"));

//if some error occurs like , don't have rights 

//uncheck readonly option in folder properties

test\u image
包含路径或一些图像数据?我只想添加一点,最好使用字符串filePath=Server.MapPath(“C:\test.txt”);