Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File copy into folder in window application

I have read a csv file from a filedialog in window application.

No i wish to copy a particular file to a folder, which is generating a problem.

the code is as follows

OpenFileDialog op1 = new OpenFileDialog();
op1.Multiselect = false;
op1.ShowDialog();
op1.Filter = "allfiles|*.csv";
txtSearchName.Text = op1.FileName;


File.Copy(op1.FileName, "C:\\Users\\skysoft\\Documents\visual studio 2010\\Projects\\MailSend\\MailSend\\CsvFile\\" + op1.FileName);

what i am doing wrong in it please help.

like image 642
Abhishek Avatar asked Dec 02 '25 23:12

Abhishek


1 Answers

i would recommend always use the @ sign before path strings to avoid problems like yours: you need 1 more back slash before "visual studio 2010". for example:

@"C:\Users\skysoft\Documents\visual studio 2010\Projects\MailSend\MailSend\CsvFile\"

also, you are giving the method

"C:\\Users\\skysoft\\Documents\visual studio 2010\\Projects\\MailSend\\MailSend\\CsvFile\\" + op1.FileName

which translate to

"C:\\Users\\skysoft\\Documents\visual studio 2010\\Projects\\MailSend\\MailSend\\CsvFile\\" + "c:\\...."

you should do Path.GetFileName(op1.FileName) as keyboardP said or op1.FileName.Substring(op1.LastIndexOf('\\'))

like image 64
No Idea For Name Avatar answered Dec 05 '25 13:12

No Idea For Name



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!