System.IO.File.Copy changes the current Directory

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Avi

    #1

    System.IO.File.Copy changes the current Directory

    Hi All,
    I am using following function to copy a file.

    System.IO.File. Copy(sourcefile ,destFile);

    I am giving absolute path in destFile. (eg. "C:\avi.txt ")

    After execution of this call, my current directory changes to "C:\".
    How can I prevent this? I want my current directory to remain
    unchanged.

    One way will be calling GetCurrentDirec tory() and SetCurrentDirec tory()
    in sequence.

    string currentdir = Directory.GetCu rrentDirectory( );
    // Copy file
    System.IO.File. Copy("c:\\a.txt ",destFile) ;
    Directory.SetCu rrentDirectory( currentdir);

    Is there any better solution to this problem.

    Thanks and Regards,
    Avi

Working...