none
The process cannot access the file because it is being used by another process.

    Question

  • Hello

    File.Move(file.a,file.b) returns an exception saying: "The process cannot access the file because it is being used by another process." I am 100% sure that no other process is using the file. About an hour ago the code worked, since then I installed a new signature maybe that's what's causing it. But I didn't find any information about that on the internet.

    Tell me, if you need more infos.
    Thanks
    Wednesday, September 03, 2008 2:28 PM

Answers

  • Hi unsintall.exe,

    Sorry that we cannot do a troubleshooting for your code snippet, as we cannot execute it.

    Since the problem is a specified file is being used by another process, well, we can check which process is using this file, to do this, consider use the Process Monitor , notice the “Path” column, and set the filter condition as "Path=the_file_want_to_monitor_path",  but first of all, restart your computer to make sure no process is access this file.

    By using Process monitor, we can check a specific file is being used by which process, and if the process is just the process that throw the exception “cannot access file…”, I believe you need to take a closely look at your code, and find if there is a open file statement without matched close file statement.

    Regards,

    Xun

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help. http://forums.msdn.microsoft.com/en-US/csharpide/thread/8e9ed0d7-11ff-402a-8489-9b5f05eeb706
    • Edited by jack 321 Friday, September 05, 2008 8:32 AM edit some
    • Marked as answer by jack 321 Tuesday, September 09, 2008 10:37 AM
    Friday, September 05, 2008 7:54 AM

All replies

  • Are you calling any File.Open statements in your code?  File.Open opens a stream that won't close unless you explicitly call close on the resulting stream.

    Give us some of the surrounding code and some of the other code that deals directly with these files.
    David Morton - http://blog.davemorton.net/
    Wednesday, September 03, 2008 2:45 PM
    Moderator
  • No, there aren't any File.Open statements. It's not possible that the file is locked.  Anyway, here is my code:


    public void ReleaseVersion(Document doc, string author) 



            { 



                if (doc.CirculationVersion == null



                    throw new DocumentFactoryException("Document not in circulation"null); 



     



                DocumentVersion current = doc.CurrentVersion; 



                if (current != null && !File.Exists(current.Path)) 



                    throw new DocumentFactoryException("Document not found: " + current.Path, null); 



                DocumentVersion circ = doc.CirculationVersion; 



                if (!File.Exists(circ.Path)) 



                    throw new DocumentFactoryException("Document not found: " + circ.Path, null); 



     



                WordConnector word = new WordConnector(); 



                if (current != null



                    word.CloseDocument(current.Path); 



                word.CloseDocument(circ.Path); 



                 



                RemoteConnector con = new RemoteConnector(_config.Connector); 



     



                circ.Status = Status.Released; 



                circ.Author = author; 



     



                if (current != null



                { 



                    if (doc.SignedVersion.LinkPath != null && File.Exists(doc.SignedVersion.LinkPath)) 



                        File.Delete(doc.SignedVersion.LinkPath); 



                     



                    current.Status = Status.Invalid; 



                    string currentPath = _GenerateDocPath(doc, current, current.FileType); 



     



                    current.Path = currentPath; 



                    con.UpdateVersion(doc.Id, current); 



                    File.Move(current.Path, currentPath); 



                } 



                string circPath = _GenerateDocPath(doc, circ, circ.FileType); 



                File.Move(circ.Path, circPath); //That is where the Exception is thrown 



                circ.Path = circPath; 



                con.UpdateVersion(doc.Id, circ); 



            }



     A few more Tests have shown that the problem occurs only with filetypes like .jpg, png, and pdf but not with Word documents. So I think it really is a signature issue.
    Thursday, September 04, 2008 5:33 AM
  • Use UnLock IT programm. (http://www.emco.is/products/unlock-it/features.php)
    Unlock locked file of folder by terminating processes, which hold lock. Locked processes detection. Integration into Windows Explorer context menu.
    Thursday, September 04, 2008 6:37 AM
  • Heureka! It not a signature issue. Although I said that I'm 100% sure that no other process is using the file it turns out that it is just not process I started which is using the file. Looking at the task manager I noticed that after each move operation involving a file with a known extension a process of the corresponding application (e.g. AcroRd32.exe after moving a pdf)  has been started. After changing the extension to something not associated with any application it works.

    Still, how do I keep the file from being found? Can I lock it somehow or tell the other applications that there is a three-headed monkey behind them to make them look away?
    Thursday, September 04, 2008 7:35 AM
  • Hi unsintall.exe,

    Sorry that we cannot do a troubleshooting for your code snippet, as we cannot execute it.

    Since the problem is a specified file is being used by another process, well, we can check which process is using this file, to do this, consider use the Process Monitor , notice the “Path” column, and set the filter condition as "Path=the_file_want_to_monitor_path",  but first of all, restart your computer to make sure no process is access this file.

    By using Process monitor, we can check a specific file is being used by which process, and if the process is just the process that throw the exception “cannot access file…”, I believe you need to take a closely look at your code, and find if there is a open file statement without matched close file statement.

    Regards,

    Xun

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help. http://forums.msdn.microsoft.com/en-US/csharpide/thread/8e9ed0d7-11ff-402a-8489-9b5f05eeb706
    • Edited by jack 321 Friday, September 05, 2008 8:32 AM edit some
    • Marked as answer by jack 321 Tuesday, September 09, 2008 10:37 AM
    Friday, September 05, 2008 7:54 AM