-1
我試圖通過檢索使用LINQ to SQL匿名類型的虛擬路徑從服務器中刪除物理照片文件,但無法正常工作。我使用ASP.NET 4.5和實體框架5.下面是我的代碼:通過匿名類型循環刪除圖片文件
//deleting all image gallery file collection
using (ProductModelEntities DB = new ProductModelEntities())
{
var picsDB = from pk in DB.Pictures
where pk.MainId == _id
select new
{
pk.ImageUrl
};
foreach (var picUrl in picsDB)
{
string fileNme = Server.MapPath(picUrl.ToString());
System.IO.File.Delete(fileNme);
}
}
失敗,因爲...?這是基本的調試。儘管它 - 它找到了網址嗎?它是否得到正確的文件名? –