Take the directory of the executable and save image in a folder inside this directory

Asked

Viewed 418 times

0

I needed to take the path of the executable and save in a folder inside the root directory where the ". exe", serving both the file programming in the "bin" and "debug" folder and when creating the installer with "Inno setup" and opening in any user-designated folder when installing the file. It is taking the name of the file and saving in "bmp" format but it is not working to pick up and save the folder 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);

1 answer

0

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

System.Environment.CurrentDirectory

Ex: txtCaminhoRaiz.Text = System.Environment.CurrentDirectory;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.