我上傳了PDF的數量,並且我在那裏存儲SQL服務器的路徑。 我需要能夠刪除保存在文件夾中的pdf文件。我已經設法讓上傳&下載工作,但刪除令我困惑。 我的代碼是...`刪除上傳的文件形式文件夾和路徑存儲在SQL服務器asp.net
protected void gridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
SqlConnection con = new SqlConnection(cs);
ProductID = gridView.DataKeys[e.RowIndex].Values["ProductID"].ToString();
//File Delete start//
using (SqlConnection con1 = new SqlConnection(cs))
{
SqlCommand cmd1 = new SqlCommand("SELECT PDF1, PDF2, PDF3 FROM Product WHERE ProductID = @ProductID", con1);
cmd1.Parameters.AddWithValue("ProductID", ProductID);
SqlDataAdapter sda = new SqlDataAdapter(cmd1);
DataTable dt = new DataTable();
sda.Fill(dt);
try
{
string pdf1 = dt.Rows[0]["PDF1"].ToString();
string pdf2 = dt.Rows[0]["PDF2"].ToString();
string pdf3 = dt.Rows[0]["PDF3"].ToString();
string strFileFullPath1 = VirtualPathUtility.ToAbsolute(pdf1);
if (File.Exists(strFileFullPath1))
{
File.Delete(strFileFullPath1);
}
string strFileFullPath2 = VirtualPathUtility.ToAbsolute(pdf2);
if (File.Exists(strFileFullPath2))
{
File.Delete(strFileFullPath2);
}
string strFileFullPath3 = VirtualPathUtility.ToAbsolute(pdf3);
if (File.Exists(strFileFullPath3))
{
File.Delete(strFileFullPath3);
}
}
你爲什麼包括一個鏈接到你的代碼的圖片,而不是僅僅把代碼本身?請解決這個問題。 –
我附上一段代碼圖片 –
我知道你做過。你爲什麼不把代碼放在問題本身?我們不想點擊一個鏈接來獲取您的代碼,讓我們看看它的圖片而不是代碼本身。請修改您的問題,以便在問題的正文中包含代碼本身。 –