saveFileDialog, select the last modified folder

Asked

Viewed 111 times

0

I would like to know how to make saveFileDialog, open my last modified folder, thus taking the operator’s job of selecting it. I tried to use this one I found in the gringo stack, but it didn’t work:

OpenFileDialog dlgOpen = new OpenFileDialog();
string initPath = Path.GetTempPath() + @"\FQUL";
dlgOpen.InitialDirectory = Path.GetFullPath(initPath);
dlgOpen.RestoreDirectory = true; 

Just follow my code:

private void button1_Click(object sender, EventArgs e)
{
    try
    {
        //abre a opção de salvar como, para selecionar a pasta
        SaveFileDialog saveFileDialog1 = new SaveFileDialog
        {
            Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif",
            Title = "Salvar o arquivo de imagem",
            InitialDirectory = @"\\M12971\Imagens$"
        };
        saveFileDialog1.ShowDialog();

        // se o nome do arquivo não for vazio, abre para salvar
        if (saveFileDialog1.FileName != "")
        {
            // salva a imagem por fileStream
            System.IO.FileStream fs =
               (System.IO.FileStream)saveFileDialog1.OpenFile();
            // Salva a imagem no formato certo
            switch (saveFileDialog1.FilterIndex)
            {
                case 1:
                    this.pictureBoxScreenshot.Image.Save(fs,
                       System.Drawing.Imaging.ImageFormat.Jpeg);
                    break;

                case 2:
                    this.pictureBoxScreenshot.Image.Save(fs,
                       System.Drawing.Imaging.ImageFormat.Bmp);
                    break;

                case 3:
                    this.pictureBoxScreenshot.Image.Save(fs,
                       System.Drawing.Imaging.ImageFormat.Gif);
                    break;
            }

            fs.Close();
        }

    }
    catch (Exception ex)
    {
        MessageBox.Show("Erro " + ex.Message);
    }
}
  • you will have to save the last folder somewhere, regedit, text file, qlqr thing, and before opening the diag, set which initial path

  • Restoredirectory should work after the first interaction, it is not starting from the last save directory?

1 answer

2


Remove InitialDirectory = @"\\M12971\Imagens$" of saveFileDialog1 and add saveFileDialog1.RestoreDirectory = true;. This should solve your problem, see an example below:

inserir a descrição da imagem aqui inserir a descrição da imagem aqui

Browser other questions tagged

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