Copy File via Save Dialog Box
The program that i wanted to do is that the application uses a Save Dialog box then chooses the directory where the user wants to copy a file... after that, the file is copied to the selected directory. Although i'm having an error "the file does not exist" when i use the Save Dialog box. But when i try not to use a dialog box and use a specific directory where I want to save a copied file, it works fine... Can anybody provide me a working code for it?

AlanRank #669 · 3.6K reputationPosted Feb 25, 2008, 12:47 AM EST
Try something like this:
string
fileToCopy = @"c:\documents\myfiletocopy.txt"; // or whatever SaveFileDialog sfd = new SaveFileDialog();sfd.FileName = fileToCopy;
sfd.Filter =
"Text files (*.txt)|*.txt|All files (*.*)|*.*";sfd.FilterIndex = 1;
sfd.RestoreDirectory =
true; if (sfd.ShowDialog() == DialogResult.OK){
System.IO.
File.Copy(fileToCopy, sfd.FileName, true);}
Silvyster Abing5 reputationPosted Feb 25, 2008, 2:30 AM EST
AlanRank #669 · 3.6K reputationPosted Feb 25, 2008, 5:19 AM EST
To start from the path in which the .exe resides, you could use this line:
string fileToCopy = Application.StartupPath + "\\" + "myfiletocopy.txt";Silvyster Abing5 reputationPosted Feb 25, 2008, 1:07 PM EST