save pdf image

3

Good afternoon.

I have a theme when trying to save a pdf document in a local folder.

With openFileDialog I'm not allowed and with itextsharp I do not understand how to do.

What I need is from my windows form, a dialog is opened, I can select a pdf document from the PC and save it in a local folder. And the path in the database, to later call it from a web application.

this way you can not:

        OpenFileDialog open = new OpenFileDialog();
        open.InitialDirectory = "C:\";
        open.Filter = "Imagen Files (*.pdf)| *.pdf|ALL Files(*.*)|*.*";
        open.FilterIndex = 1;

        if (open.ShowDialog() == DialogResult.OK)
        {
            if (open.CheckFileExists)
            {
                string ruta = @"C:\Users\matias\Documents\Visual Studio 2015\Projects\ProyectoFinal\ProyectoFinal\Imagenes\PdfVentas\";
                string nombre = System.IO.Path.GetFileName(open.FileName);

                System.IO.File.Copy(nombre, ruta);

            }

        }

And with itext I do not realize how to do it, because I created a document, I can not select it:

     Document doc = new Document(PageSize.LETTER);
     PdfWriter writer = 
             PdfWriter.GetInstance(doc, new FileStream(@"C:\prueba.pdf",
             FileMode.Create));
     doc.open();

If someone could give me a hand I would appreciate it.

Thank you very much.

Greetings.

    
asked by matias ludueña 13.10.2016 в 16:46
source

1 answer

0

The problem is that in the copy you do not tell him how the file should be called. The destination route must include the name.pdf

Try this way:

    OpenFileDialog open = new OpenFileDialog();
    open.InitialDirectory = "C:\";
    open.Filter = "Imagen Files (*.pdf)| *.pdf|ALL Files(*.*)|*.*";
    open.FilterIndex = 1;

    if (open.ShowDialog() == DialogResult.OK)
    {
        if (open.CheckFileExists)
        {
            string ruta = @"C:\Users\matias\Documents\Visual Studio 2015\Projects\ProyectoFinal\ProyectoFinal\Imagenes\PdfVentas\";

            System.IO.File.Copy(open.FileName, ruta + open.SafeFileName);

        }

    }
    
answered by 13.10.2016 / 17:06
source