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:
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
2010-03-09 12:15:18
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
2010-03-10 05:09:26
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
2010-03-10 05:11:52
@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
2010-03-10 06:25:24
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
2010-03-10 06:38:29
@zoya: I updated my answer.
Fredrik Mörk
2010-03-10 09:24:57
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
2010-03-11 09:11:30
@zoya: you are welcome. Regarding DVD burning in XP I have no experience or knowledge ad all, unfortunately.
Fredrik Mörk
2010-03-11 09:34:49
thanks anyways......
zoya
2010-03-11 10:12:31