views:

162

answers:

1

Hi, In my application, i am downloading file from DMS system to my server. Once the file gets downloaded, on some environment, the iis keeps lock of the file and when the application tries to redownload the file and put the file on same location, an error is generated that file is being used by another process. Following is the code :

    Try
            Directory.CreateDirectory(serverPath.ToString)

            downloadFilePath = serverPath.ToString & fileName
            fileDownloaded = estimateFacade.DownloadFiles(dmsLinkID, downloadFilePath)


    Catch threadex As System.Threading.ThreadAbortException

    Catch ex As System.Exception
        lblDownloadingcomment.Text = ex.Message
        trButtons.Visible = True
        btnDownload.Visible = False
        'Throw ex
    Finally
        If Not fileDownloaded Is Nothing Then
            fileDownloaded.Close()
        End If
    End Try
+1  A: 

You may want to verify that it is your application that is locking the file. The excellent, free Process Explorer tool from Microsoft has a "Find" menu option where you can type in the name of the file and see which processes have a lock on it.

Edit:

I just noticed that you stuff ThreadAbortException's. Please read Joe Duffy's book for why this is a relatively pointless exercise.

David Gladfelter
It is been locked by iis, as when i restart the iis, it releases the lock.
Ankit
+1 Additionally sometimes many applications keep the last download location locked (i.e. they have a handle to that location) for future use. Not sure if IIS does the same.
Ganesh R.