Reputation: 207
I am removing the image from kendo upload control.
This is my code
public ActionResult Remove(string[] fileNames)
{
if (fileNames != null)
{
foreach (var fullName in fileNames)
{
var fileName = Path.GetFileName(fullName);
var physicalPath = Server.MapPath(Path.Combine(("~/AssetAttachments"),fileName));
if (System.IO.File.Exists(physicalPath))
{
System.IO.File.Delete(physicalPath);
}
}
}
return Content("");
}
Physicalpath i have is E:\karthik related\JPL\Dev\Src\AssetTrackingSystem\AssetTrackingSystem\AssetAttachments\Attach3.jpg
Even though file and directory available
if (System.IO.File.Exists(physicalPath))
is returning false and coming out of condition.
Your help will be appreciated.
Upvotes: 2
Views: 2179
Reputation: 3787
Try this:
foreach (var fullName in fileNames)
{
var physicalPath = System.IO.Path.Combine(HttpContext.Current.Server.MapPath("~/AssetAttachments"), fullName);
if (System.IO.File.Exists(physicalPath))
{
System.IO.File.Delete(physicalPath);
}
}
Upvotes: 6
Reputation: 8020
Try with this,
FileInfo fi = new FileInfo(Path.Combine(("~/AssetAttachments"),fileName));
if (fi.Exists)
{
fi.Delete();
}
Upvotes: 1