Closed Thread
Results 1 to 3 of 3

Thread: File.Move throws exception

  1. #1
    Dumpen is offline Newbie
    Join Date
    Jun 2008
    Posts
    14
    Rep Power
    0

    File.Move throws exception

    Hello all

    I am using WebMethod and File.Move

    But my problem is the file is being locked by the WebMethod and it cannot be moved again (I want to rename it, not move it)

    The exception thrown is "The process cannot access the file because it is being used by a another process"

    How do I solve this?

    I probably googled for half an hour

    Here is my code:
    Code:
        [WebMethod]
        public void EditFile(string FilePath, string NewName, string OldName)
        {
            File.Move(FilePath + OldName, FilePath + NewName);
        }

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    cdg10620's Avatar
    cdg10620 is offline Programming Expert
    Join Date
    Jun 2009
    Location
    Texas
    Posts
    387
    Blog Entries
    3
    Rep Power
    12

    Re: File.Move throws exception

    Are you using another method to access the path of the file or get the file name? There has to be something else going on before this method is called in order for that error to be thrown. Another thing you may want to try is see if you can use File.Copy and copy the old file to the new name and then use File.Delete to remove the old one. See if that throws an error. It's not the best method but you can use that for debugging to see if it gives the same error message.

    Let me know if you need any further assistance.
    -CDG10620
    Software Developer

  4. #3
    gokuajmes's Avatar
    gokuajmes is offline Programming God
    Join Date
    Jan 2010
    Location
    India
    Posts
    516
    Blog Entries
    5
    Rep Power
    12

    Re: File.Move throws exception

    I am sure that you left a FileReader or FileStream instance object left open in your code.
    use the

    Code:
    FileStream fs=new FileStream();
    fs.close(); //use this to close the file handles

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. move_uploaded_file(images/) [function.move-uploaded-file]: failed to open stream
    By Julien Duponte in forum Database & Database Programming
    Replies: 21
    Last Post: 04-28-2011, 04:09 PM
  2. MOVE FILE
    By psm in forum Managed C++
    Replies: 0
    Last Post: 04-04-2010, 01:28 PM
  3. Move a file?
    By Crane in forum PHP Development
    Replies: 1
    Last Post: 03-03-2007, 04:57 PM
  4. Move a file in Perl
    By Cosmet in forum Perl
    Replies: 3
    Last Post: 02-12-2007, 08:43 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts