Can not delete file using ASP .NET 2.0 from the images directory within the website

Hi,

I use a form to upload an image to a directory on my site
(~/Images/UserName/file1.jpg). Using Server.mapPath function i get the
Physical path and save the file using
FileUpload1.PostedFile.SaveAs(filePath) function. The file is saved fine.

I also keep an daabase entry to store the virtual path
(~/Images/UserName/file1.jpg) for that specific user entry. The problem is
when i try to use File.Delete(Server.MapPath("~/Images/UserName/file1.jpg"))
to delete the file i get this error

------------------------------------------------------------ -----
The process cannot access the file
'C:\inetpub\wwwroot\WebSite\Images\UserName\file1.jpg' because it is being
used by another process.
------------------------------------------------------------ -----

I can not get past the error. So , plz help. Thnx in advance.
Anjan Bhowmik [ Mo, 31 März 2008 06:23 ] [ ID #1932585 ]
Microsoft » microsoft.public.dotnet.framework.aspnet » Can not delete file using ASP .NET 2.0 from the images directory within the website

Vorheriges Thema: Modifying Data in a GridView Web Server Control
Nächstes Thema: datagrid question