I would like to know how to do saveFileDialog, open my last modified folder, thus taking the job of the operator to select it. I tried to use this one that I found in the gringo stack, but it did not work:
OpenFileDialog dlgOpen = new OpenFileDialog();
string initPath = Path.GetTempPath() + @"\FQUL";
dlgOpen.InitialDirectory = Path.GetFullPath(initPath);
dlgOpen.RestoreDirectory = true;
Here is 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);
}
}