I have a back up folder and a main folder in my project. I am giving an option to user in main menu to open file from backup folder. For that i have written code:
string[] paths;
string fullpath = "";
paths = Directory.GetFiles(backuppath);
foreach (string backupfilepath in paths)
{
if (path.EndsWith(".txt"))
fullbackupfilepath = backupfilepath;
}
Here backuppath is the path of the backup file.
Now i copy this back up file in main project folder:
File.Copy(fullbackupfilepath, mainprojectfilepath);
But i get the error that Could not find file C:\Users\me\Desktop\csharpproject\bin\debug\BackupProject.txt
Why is it going in bin debug folder when my project is in MyDocuments\Myproject. There is backupfolder inside this Myproject folder.
Please help with a solution.
If you use relative path rather than absolute path, in runtime the base folder is the folder where the executable is located. In debug mode it’s bin/debug.
It’s not advisable to have user files in the programs directory at all. I.e. if you install your program in Windows Vista or 7 programms folder, you will need admin rights to write into this directory.
You should have a look at
Environment.SpecialFolder.This piece of code will generate a path for the current user, where you could store the files.