CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2008
    Posts
    54

    cannot delete image file using File.Delete

    I just try a simple method to delete file, File.Delete("path to file") can delete some types of file, but every time I use it to delete an image, it pop an error like "The path is denied/ file is currently in use"
    I find it very strange, no process is using that image and in my project, no code makes use of that image, only 1 line File.Delete, so what is that error and how to overcome this ?
    One more thing, I saw that error when programming in Vista, then I tried it on XP and the image was deleted smoothly, can anyone explain this

  2. #2
    Join Date
    Jun 2002
    Posts
    936

    Re: cannot delete image file using File.Delete

    Did you check the attribute to make sure the file is not protected? You may need do that or clear the attribute for the file first.

  3. #3
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: cannot delete image file using File.Delete

    Is the image in the program files folder or beneath it ?

    Vista restricts access to the program files folder and other folders unless the application is run in administrator mode.

    This causes problems with applications which write to their installation folder in program files, or any sub folder of the installation folder.

    Instead you should write application files to a sub folder in the folder given by

    Code:
    Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  4. #4
    Join Date
    Aug 2008
    Posts
    54

    Re: cannot delete image file using File.Delete

    thanks you 2 and the answers're NO, that image is not protected and is not under Program Files folder, I put it in an ordinary folder and without any attribute (I can delete it using command in Windows context menu but... can not use File.Delete)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured