views:

126

answers:

2

i have the files situated in the listview now i want to copy those files to a directory in windows.. how this action can be performed??

A: 

you have a File.copy and File.create in system.io

Pablo Castilla
A: 

I don't know what the data in your ListView looks like, but in general you should use File.Copy:

string sourceFile = @"c:\sourcedir\file.ext";
File.Copy(sourceFile, Path.Combine(@"c:\targetdir", Path.GetFileName(sourceFile)));

Update
Here is an example of iterating of the the items in a ListView, copying files with names fetched from a sub item (this is assuming the file name is in the third column; change the index number to fetch the Sub Item containing the file name in your code):

foreach (ListViewItem item in listView1.Items)
{
    string sourceFile = item.SubItems[2].Text;
    File.Copy(sourceFile, Path.Combine(@"c:\targetdir", Path.GetFileName(sourceFile)));
}
Fredrik Mörk
the data is Sno,Case_id,File... in file column i have placed the full path of the file... now i want to send the complete data to the diectory..how can i do that??
zoya
sir ur answer is about to copy the file to dir...but my question is to copy the files placed in listview to directory..
zoya
@zoya: you probably do not have any files placed in your list view; you proably have *file names*. All you need to do is to read the file name from each `ListViewItem`, use that value as I use `sourceFile` in my code sample. I cannot tell you how to do that, since you have not shown how you populate the `ListView`.
Fredrik Mörk
im having the file path placed in the listview..and i want to send items situated in that file path to the directory..so how can i do that...im populating the listview with listview.items.add() cmd..but thats not the issue..just take it as the items are already placed in the listview at run time and now i need to perform the action to send the entries in the listview to directory..im thinking of using hash table concept but im not familiar with it can u help me out plzz...
zoya
@zoya: I updated my answer.
Fredrik Mörk
thank u so much......for ur updates..its really helpful for me...i want to ask u one major question related to my project..i have posted the question related to that also but didnt get any satisfactory ans..the ques. is about to burn dvd using c#.net in Windows XP sp2/sp3..all i have tried is..imapi2 and XPburn component..but neither of them worked fine in XP.. imapi2 is working in vista and windows7 but not in XP??
zoya
@zoya: you are welcome. Regarding DVD burning in XP I have no experience or knowledge ad all, unfortunately.
Fredrik Mörk
thanks anyways......
zoya