?
Solved

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

Posted on 2003-03-14
4
Medium Priority
?
182 Views
Last Modified: 2010-04-15
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;
               }          }
     }

     
}
0
Comment
Question by:dennis_skidmore
2 Comments
 
LVL 2

Expert Comment

by:AndrewK
ID: 8138885
Complete shot in the dark - have you tried using the string literal @ ?

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

0
 
LVL 1

Accepted Solution

by:
zubok32 earned 400 total points
ID: 8172647
Hi. Check if your application has access permissions to this file.
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses
Course of the Month8 days, 13 hours left to enroll

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question