VBForums >
.NET >
C# > [RESOLVED] File.Copy() and other backuping information
Click to See Complete Forum and Search --> : [RESOLVED] File.Copy() and other backuping information
PsychoticPsymon
Apr 26th, 2006, 04:35 PM
I have the person locate files on the harddrive using the dialog boxes located in the SDK, however I have a problem. I add them to listboxes then use for...next loops to iterate through the lists, copying and pasting the files. Unfortunately, so far all attempts at that last part of drudged up nothing but exceptions inolving the existance of the file. I'm kinda stuck and the program is for a small business that a family member owns, so any help would be greatly apprectiated.
conipto
Apr 26th, 2006, 05:07 PM
Are they populating the listbox properly? can you post some code where your exception throws?
Bill
PsychoticPsymon
Apr 26th, 2006, 09:36 PM
IMPORTANT NOTE: I haven't added support for backing up folders and am not testing it.
VC#.net 2003
"System.IO.Exception
Target directory already exists"
I did put true in the file.copy method.
lstCopyFiles is the listbox that saves the file paths. lstDestination is the chance for multiple backups to be created. First block of code is what saves the path.
private void AddDeterminate(bool AddFile)
{
string FileName = "";
if(AddFile == true)
{
diaFiles.ReadOnlyChecked = true;
diaFiles.Multiselect = true;
diaFiles.InitialDirectory = "C:";
diaFiles.CheckFileExists = true;
diaFiles.CheckPathExists = true;
diaFiles.Title = "Specify files to be backed up";
diaFiles.ShowDialog(this);
FileName = diaFiles.FileName.ToString();
}
else
{
diaFolder.Description = "Specify folders to be backed up";
diaFolder.ShowDialog(this);
FileName = diaFolder.SelectedPath.ToString();
}
SaveUpdate = false;
lstCopyFiles.Items.Add(FileName);
}
And this is the exception throwing code:
private void BackUp()
{
lstDestination.SelectedIndex = 0;
int iCount;
int iCount2;
for(iCount = 0; iCount < lstCopyFiles.Items.Count;++iCount)
{
for(iCount2 = 0; iCount2 < lstDestination.Items.Count; ++iCount2)
{
lstCopyFiles.SelectedIndex = 0;
File.Copy(lstCopyFiles.SelectedItem.ToString(), lstDestination.SelectedItem.ToString(),true);
}
lstCopyFiles.Items.RemoveAt(0);
}
}
conipto
Apr 27th, 2006, 05:03 PM
File.Copy(lstCopyFiles.SelectedItem.ToString(), lstDestination.SelectedItem.ToString(),true);
On that line, is lstDestination.SelectedItem.ToString() giving you a full path or just the directory to put it in. It may be that you are only telling it the target directory, when you need to specify the whole thing..
I.e, for parameter 1: "C:\BILL\JOE.TXT"
for parameter 2: "C:\JOE\JOE.TXT" is ok but "C:\JOE\" is not ok..
Bill
PsychoticPsymon
Apr 28th, 2006, 07:03 PM
!!!
>.<
If I may be so upfront, Conipto, I love you.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.