Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Errors
class Program
{
static void Main(string[] args)
{
bool fileExists = false;
 
string thePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

string thefile = thePath + @"\y.txt;
 
fileExists = File.Exists(thefile);
 
if (fileExists)
{
Console.WriteLine("The file exists");
 
}
else
{
Console.WriteLine("The file does not exist,creating it");
File.Create(thefile);
 

 
}
 

if (fileExists)
{
string newpath = Environment.GetFolderPath (Environment.SpecialFolder.MyComputer);
string newfile = newpath + @"\newlife.text";
Console.WriteLine("It was created on {0}",File.GetCreationTime(thefile));
Console.WriteLine("It was last acessed on {0}",File.GetLastAccessTime(thefile));
Console.WriteLine("Moving the file...");
File.Move(thePath,newpath); // why i have error in this line???
}
 
Console.ReadLine();
}
 
}
Posted 20-Nov-12 12:34pm
mibetty480
Comments
Sergey Alexandrovich Kryukov at 20-Nov-12 18:45pm
   
Error or exception? Please, complete exception or error information. File not found, or something?
--SA
mibetty at 20-Nov-12 18:52pm
   
the error is this :
 

A empty file name its not valid .
Name of the parameter: destFileName
Sergey Alexandrovich Kryukov at 20-Nov-12 19:17pm
   
This is not error, this is exception. Know the difference?
So, looks like newpath is empty. Is does not seem to be so in this code. Are you sure you show the same code which causes the problem? After all, execute it under the debugger, and you will see everything.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Your calculated file name is thefile, but you are using thePath in the call to File.Move. Always use the debugger. The code looks very fluffy, inaccurate and redundant. Why creating a file in one place and them moving. Generally, hard-coded file names are not useful, but you are using right things, such as Environment.SpecialFolder. You need to plan the code more thoroughly and make it mode combed…
 
—SA
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

I think Your problem is on this line


string newpath = Environment.GetFolderPath (Environment.SpecialFolder.MyComputer);


The My Computer folder.

The MyComputer constant always yields the empty string ("") because no path is defined for the My Computer folder.
 
Please refer the following link..


http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx[^]
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 475
1 OriginalGriff 280
2 BillWoodruff 230
3 CPallini 220
4 ChauhanAjay 149
0 OriginalGriff 6,609
1 Sergey Alexandrovich Kryukov 6,240
2 CPallini 5,180
3 George Jonsson 3,574
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 20 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100