here에서 미리보기 이미지를 표시하도록 도우미를 구현했습니다. 그때 썸네일을 표시하지 않도록 설정하면파일 (jpeg)을 삭제할 수 없습니다
// HTTP POST: /Photo/Delete/1
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Delete(int id, string confirmButton)
{
var path = "~/Uploads/Photos/";
Photo photo = photoRepository.GetPhoto(id);
if (photo == null)
return View("NotFound");
FileInfo TheFile = new FileInfo(Server.MapPath(path + photo.PhotoID + ".jpg"));
if (TheFile.Exists)
{
photoRepository.Delete(photo);
photoRepository.Save();
TheFile.Delete();
}
else return View("NotFound");
return View();
}
파일이 삭제됩니다 : 다음 축소판,이 컨트롤러를 호출 삭제 링크가 있습니다. 그렇지 않으면 오류가 발생합니다.
System.IO.IOException: The process cannot access the file 'C:\Documents and Settings\ilija\My Documents\Visual Studio 2008\Projects\CMS\CMS\Uploads\Photos\26.jpg' because it is being used by another process.
또한 파일 삭제 기능이 제대로 작성되었는지 잘 모릅니다. 인터넷에서 검색 할 때 나는 모두 사용할 수없는 File.Delete(TheFile);
을 사용하며 TheFile.Delete();
을 사용합니다. File.Delete(TheFile);
을 사용할 때 다음 오류가 발생합니다 :
Error 1 'System.Web.Mvc.Controller.File(string, string, string)' is a 'method', which is not valid in the given context C:\Documents and Settings\ilija\My Documents\Visual Studio 2008\Projects\CMS\CMS\Controllers\PhotoController.cs 109 17 CMS
내가 여기에 뭔가를 놓친가요?
엄지 손가락 생성기가 파일을 사용한다는 것을 알고 있는데, 아마도 File.Delete()와 관련이 있다고 생각합니까? –
나머지 코드는 모르지만 썸네일 gen이 어떻게 든 파일의 핸들을 여는 것으로 가정합니다 (예 : Bitmap 클래스 사용). 파일을 사용하여 축소판을 생성 한 후에는 삭제할 수 있도록 비트 맵 클래스 (또는 파일을 사용하는 클래스)를 .close()해야합니다. –
정확히 무엇을 닫아야합니까? 링크에 내 질문에 게시 클래스 비트 맵 비트 맵 = 새로운 비트 맵 (FilePath); 하지만 bitmap.Close()가 작동하지 않습니다. –