Reputation: 281
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
Upvotes: 0
Views: 1088
Reputation: 4213
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.
Upvotes: 1