Question : C# copy files from one folder to another

I have a gridview that lists all of the files in a folder. The gridview also shows a checkbox next to each file. What I need to accomplish is giving the use the ability to check any nunber of files listed, then when they click on the Copy button, the checked files will be copied to another folder. I've had it working in that every file is copied, but I need it to only be the selected files. The other feature needed is once the Copy button is clicked, the uses is asked where to copy the files to before they are copied. Is there any way to do all of this? I've been utilizing this site quite a bit lately. Thanks for all of the help. I provided code for the copy button below, but it's not complete yet, obviously.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
public void copyButton(object sender, EventArgs e)
{
for (int i=0; i < this.GridView1.Rows.Count; i++)
{
CheckBox cb = (CheckBox)this.GridView1.Rows[i].FindControl("CheckBox1");
if (cb.Checked)
{
DataKey keyForThisRow = GridView1.DataKeys[i];
string filename = (string)keyForThisRow[0];
}
}
}

Answer : C# copy files from one folder to another

Copying only Selected Files
The code snippet provided may work correctly if you place the file copying code just after obtaining the file name. Make sure that the variable "filename" should be fully-qualified local or network path (UNC-based) of the source file rather than only the name. For copying a single file use the provided in code snippet.

Confirming the Target Path
For this purpose, you may have to utilize another page or same page or some modular pop up to host list/browse/selection of target paths available within the server machine where the files could be copied.
1:
2:
3:
File.Copy("SourceFilePathAndNameWithExtension", "TargetFilePathAndNameWithExtension")
'With forced overwrite
File.Copy("SourceFilePathAndNameWithExtension", "TargetFilePathAndNameWithExtension", True)
Random Solutions  
 
programming4us programming4us