Good day. I had such a problem: you need to save the files in such a way that the selected file is automatically saved to a specific folder (in my case, "Photo"). But I can't do it ... Thank you in advance for your help.

  • It is not clear. If the folder is defined and the file is a dialogue and not necessary, save it. Or is it necessary to show a certain folder in the dialogue? InitialDirectory to help ... And what does not work out? - Alexey Sonkin
  • Well, I had to use SaveFileDialog to select a file, and when I clicked the "Save" button, the file should be copied to the folder next to the file. InitialDirectory tried, but probably not there I am writing it (or I do not correctly specify the path) saveFileDialog1.InitialDirectory = ("\ Photo") - Qwermakarenko
  • There you have to set the full path - which you can get, in my opinion, from Application.StartupPath - Alexey Sonkin
  • Never used ... Could you give an example of using Application.StartupPath? I would be very grateful - Qwermakarenko
  • msdn.microsoft.com/ru-ru/library/… - there are examples of almost everything in msdn) - Alexey Sonkin

1 answer 1

The question is canceled, done differently, in two buttons - one opens for the pre-view, the second saves:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim myStream As Stream Dim saveFileDialog1 As New SaveFileDialog() saveFileDialog1.Filter = "Изображение (*.jpg)|*.jpg| Изображение (*.gif)|*.gif " saveFileDialog1.FilterIndex = 1 saveFileDialog1.RestoreDirectory = True If saveFileDialog1.ShowDialog() = DialogResult.OK Then Dim fs As System.IO.FileStream = CType _ (saveFileDialog1.OpenFile(), System.IO.FileStream) Select Case saveFileDialog1.FilterIndex Case 1 Me.PictureBox1.Image.Save(fs, _ System.Drawing.Imaging.ImageFormat.Jpeg) Case 2 Me.PictureBox1.Image.Save(fs, _ System.Drawing.Imaging.ImageFormat.Gif) End Select fs.Close() End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click OpenFileDialog1.Filter = "Все файлы (*.*)|*.*" If OpenFileDialog1.ShowDialog() = DialogResult.OK Then PictureBox1.Image = System.Drawing.Image.FromFile(OpenFileDialog1.FileName) End If End Sub 

True, since I wanted to fail ... Well, it's not scary;)