Link to home
Start Free TrialLog in
Avatar of dennis_skidmore
dennis_skidmore

asked on

File not found error - for any file I try to copy or read

Help! I get a file not found error regardless of what file I look for or what method I use (copy, read, etc.)! I am running the following code and have tried to reduce to the simplest possible case
(root directory, short file name). I am working on my local pc and the file is on the same pc. I've included the escape character. But whatever I try, I get the error:

'Could not find file "c:\test.txt" '


using System;
using System.IO;


namespace ValidateGPCFile
{
     /// <summary>
     /// Summary description for clsFileManipulation.
     /// </summary>
     public class clsFileManipulation
     {     public string Message;

          // Default constructor:
          public clsFileManipulation()
          {
                         }

          // copy method:
          public void CopyFile()
          {
                         
               try
               {
                    //next line always produces 'cannot find file "c:\test.txt" error
                    File.Copy("c:\\test.txt", "c:\\test1.txt", true);                                            Message = "Valid";
               }
               catch (FileNotFoundException ex)
               {  
                                //the code always goes here
                    Message = "Invalid. " + ex.Message;
               }          }
     }

     
}
Avatar of AndrewK
AndrewK

Complete shot in the dark - have you tried using the string literal @ ?

File.Copy(@"c:\test.txt", @"c:\test1.txt", true);

ASKER CERTIFIED SOLUTION
Avatar of zubok32
zubok32

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial