Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0The process cannot access the fileThe process cannot access the file
Previous
 
Next
New Post
6/9/2009 2:20 PM
 

Hi all,

i've created a module to use some own web methods. Everything is working fine eexcept one thing.

In my method i've created a file:

Dim newFileWriter As IO.FileStream = Nothing
newFileWriter = New IO.FileStream(destFilePath, IO.FileMode.Create, IO.FileAccess.Write)
newFileWriter.Write(bytes, 0, bytes.Length)
newFileWriter.Flush()
newFileWriter.Close()
newFileWriter.Dispose()
newFileWriter = Nothing

This part is working fine.

At the end of my method i want to delete this file:

Dim filename As String = Path.Combine(dataPath, objZipEntry.Name)
If IO.File.Exists(filename) = True Then
 Try
  FileSystemUtils.DeleteFile(filename)
  '// or this version   ->IO.File.Delete(filename)
 Catch ex As Exception
  Return "Could not delete destination File:" + filename + vbCrLf + "error:" + ex.Message
 End Try
End If

On thi part i will get the following error: "The process cannot access the file 'C:\Inetpub\DotNetNuke\Portals\0\DatabaseUploads\ADRESSE.xml' because it is being used by another process."

I don't know where the prodblem ist. Can anybody help ?

 
New Post
6/9/2009 3:25 PM
 

What do you do with the file in between creating it and deleting it? If you are just reading the .xml file the reader may still have the file open.

If you are only using the contents of the file, one must ask why you need to write the file then delete it. Unless two separate processes/procedures need to access the file you could simply pass the file contents around in your code.

I hope this is of some help to you.


Dwayne J. Baldwin
 
New Post
6/9/2009 4:15 PM
 

I completely agree with Dwayne, if you can avoid dumping to a file in the first place it is your best bet!

However, if you cant here is my experince with this issue. I ran into this same problem a while back working on the IWeb module. It turns out this is more of an issue with IIS than with your code. You can even see this error appear in the DNN file manager window sometimes. I was not able to find any great solution to this problem (nor was anyone else I spoke to about it). So eventually I just decided (and yes I cringe saying this as much as you do reading it) to loop until I was able to delete the file. Typically after a few repeated requests to delete IIS will release the file. The longest running loop I have seen is right around a second.

Let me state very clearly, I am not happy with this solution but it is the best I could come up with and no one could give me a better answer. Your situtaion may be different and you might try doing a scheduled "clean up" process using the DNN scheduler, but that wouldnt work in my case.

 

 

 
New Post
6/10/2009 4:46 AM
 

Hi, thx for helping.

What i want to do is to upload a zip file and extract it. after extraction the file should be deleted. I've taken a look into the IWeb code and create a new delete method. Everything is working fine now.

THX all for helping. Here is my code:

        Public Shared Function deleteFile(ByVal filename As String) As String
            Dim ret As String = ""

            If IO.File.Exists(filename) = True Then
                Dim timedOut As Boolean = False
                Dim deleted As Boolean = False
                Dim starttime As DateTime = Now
                Do Until deleted OrElse timedOut
                    Try
                        FileSystemUtils.DeleteFile(filename, GetPortalSettings)
                        IO.File.Delete(filename)
                        deleted = True
                    Catch ex As Exception
                        deleted = False
                        timedOut = DateAdd(DateInterval.Second, Setting_MaxSeconds, starttime) < Now
                        If timedOut Then
                            ret = "Could not delete destination File:" + filename + vbCrLf + "error:" + ex.Message
                            Exit Do
                        End If
                    End Try
                Loop
            End If

            Return ret
        End Function

 
New Post
6/10/2009 5:25 AM
 

the issue is actually not with IIS, but with the ASP.NET file monitor. Actually a delete loop is not such a bad solution...


Erik van Ballegoij, Former DNN Corp. Employee and DNN Expert

DNN Blog | Twitter: @erikvb | LinkedIn: Erik van Ballegoij on LinkedIn

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0The process cannot access the fileThe process cannot access the file


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out