Get the executable directory and save image to a folder inside this directory

0

I needed to get the executable path and save it to a folder inside the root directory where ".exe" is located, serving both the programming of the file in the "bin" and "debug" folder and the time to create the installer with the "inno setup" and open in any folder designated by the user at the time of installing the file. It is taking the name of the file and saving it in the format "bmp" but the catch and save part is not working in the directory of the executable see my code below

 string pastaimagem = "imagem";
 string appPath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
 Bitmap bmp = new Bitmap(openFileDialog1.FileName);
            Bitmap bmp2 = new Bitmap(bmp, pictureBox2.Size);
            pictureBox2.Image = bmp2;
            string pasta = appPath + pastaimagem;
            if (!Directory.Exists(pasta))
            {


                Directory.CreateDirectory(pasta);

            }          

            pictureBox2.Image.Save(pasta + txtCod.Text + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);
    
asked by anonymous 25.09.2018 / 02:46

1 answer

0

Greetings. To get the directory path either in the debug or when the program is already running on some PC use the command asegui:

System.Environment.CurrentDirectory

Ex: txtCaminhoRaiz.Text = System.Environment.CurrentDirectory;
    
25.09.2018 / 04:02