DirectoryInfo and FileInfo classes locking files

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David Turner

    DirectoryInfo and FileInfo classes locking files

    I have created an ASP.NET page that uses the
    System.IO.Direc toryInfo.GetFil es() method to get a list of files in a
    specific directory on our web server. (I simply use this list to build some
    javascript code). I'm never opening the files or accessing them in any
    other way.

    Problem is, that once this ASP.NET page is accessed, we can then no longer
    delete or rename any of the files in that directory unless we restart IIS.

    If I try and delete them using the System.IO.File. Delete() method I get the
    following exception:

    System.IOExcept ion
    The process cannot access the file "..." because it is being used by another
    process.

    Any Ideas?


  • SR

    #2
    DirectoryInfo and FileInfo classes locking files

    Hi

    Strange. I tried this on my machine(running ASP.Net1.1)
    and it workd fine. Im able to delete the files even after
    the page is accessed!!!!

    watch for linewraps

    Dim l_objDirInfo As New DirectoryInfo
    (TextBox1.Text)
    Dim l_objFilesInfo( ) As FileInfo =
    l_objDirInfo.Ge tFiles()
    Dim l_objFileInfo As FileInfo
    For Each l_objFileInfo In l_objFilesInfo
    Response.Write( l_objFileInfo.N ame)
    Next
    l_objDirInfo = Nothing

    Are u opening file handles elsewhere by mistake!!!

    regards,

    sr
    [color=blue]
    >-----Original Message-----
    >I have created an ASP.NET page that uses the
    >System.IO.Dire ctoryInfo.GetFi les() method to get a list[/color]
    of files in a[color=blue]
    >specific directory on our web server. (I simply use this[/color]
    list to build some[color=blue]
    >javascript code). I'm never opening the files or[/color]
    accessing them in any[color=blue]
    >other way.
    >
    >Problem is, that once this ASP.NET page is accessed, we[/color]
    can then no longer[color=blue]
    >delete or rename any of the files in that directory[/color]
    unless we restart IIS.[color=blue]
    >
    >If I try and delete them using the System.IO.File. Delete[/color]
    () method I get the[color=blue]
    >following exception:
    >
    >System.IOExcep tion
    >The process cannot access the file "..." because it is[/color]
    being used by another[color=blue]
    >process.
    >
    >Any Ideas?
    >
    >
    >.
    >[/color]

    Comment

    • David Turner

      #3
      Re: DirectoryInfo and FileInfo classes locking files

      My bad!

      The javascript that I was building actually referenced another aspx page for
      each image, and I was using the image.fromfile method which was holding onto
      the file. As soon as I switched to the image.fromstrea m method, things
      started working great.


      Comment

      Working...