1
I need to select PDF files with the openFileDialog
and save them in a specific directory set in a string
in Properties.Settings
, but the code below does not work.
private void btAnexarArquivo_Click(object sender, EventArgs e)
{
// Displays an OpenFileDialog so the user can select a Cursor.
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "Arquivo PDF|*.pdf";
openFileDialog1.Title = "Selecione o arquivo PDF";
// Show the Dialog.
// If the user clicked OK in the dialog and
// a .CUR file was selected, open it.
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string diretorio = openFileDialog1.InitialDirectory;
string destino = Properties.Settings.Default.Pasta + ticket + ".pdf";
FileInfo oFile = new FileInfo(destino);
if (oFile.Exists)
{
oFile.Delete();
}
// To move a file or folder to a new location:
System.IO.File.Copy(diretorio, destino);
}
}
Displays the following error:
What do I do to fix?
How is the result of the variables
diretorio
anddestino
, could post please?– Pedro Paulo
The variable
diretorio
I picked up fromopenFileDialog1.InitialDirectory;
I believe there’s the mistake, and thedestino
would be as an example:\\192.168.10.116\MarcaBus\Arquivos\Comprovantes\arquivo.pdf
– Marlon Pereira
Change
openFileDialog1.InitialDirectory;
foropenFileDialog1.FileName;
– Pedro Paulo
The problem is in this penFileDialog1.Initialdirectory line, it has to be Filename.
– Sérgio Sereno