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.
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('\\'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With