save picture without open file dialog over and over

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • keyvan
    New Member
    • Nov 2012
    • 2

    save picture without open file dialog over and over

    i want to save picture in drive but i only want to open dialog box once at the begging and after the user can save image without open file dialog
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    That would pose a huge security risk because it would allow a person to download almost anything to a user's computer without their awareness of what is being downloaded.

    The usual way to do this would be to zip all the files and have them download one zip file.

    Comment

    • zmbd
      Recognized Expert Moderator Expert
      • Mar 2012
      • 5501

      #3
      Rabbit,
      Might this instead be like Access or Excel where there is a default folder location?

      KeyVan,
      Bytes is not a code writing nor homework service. Please provide a much more detailed description of what you are really after and please post your code - remember to format it using the <CODE/> button in the toolbar.

      Comment

      • keyvan
        New Member
        • Nov 2012
        • 2

        #4
        hi i use this method for load and save picture.
        Code:
        private void button2_Click(object sender, EventArgs e)
                { // Displays a SaveFileDialog so the user can save the Image
                    // assigned to Button2.
                    /*SaveFileDialog saveFileDialog1 = new SaveFileDialog();
                    saveFileDialog1.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif";
                    saveFileDialog1.Title = "save picture";
                    saveFileDialog1.ShowDialog();
        
                    // If the file name is not an empty string open it for saving.
                    if (saveFileDialog1.FileName != "")
                    {
                        // Saves the Image via a FileStream created by the OpenFile method.
                        System.IO.FileStream fs =
                           (System.IO.FileStream)saveFileDialog1.OpenFile();
                        // Saves the Image in the appropriate ImageFormat based upon the
                        // File type selected in the dialog box.
                        // NOTE that the FilterIndex property is one-based.
                        switch (saveFileDialog1.FilterIndex)
                        {
                            case 1:
                                this.button2.Image.Save(fs,
                                   System.Drawing.Imaging.ImageFormat.Jpeg);
                                break;
        
                            case 2:
                                this.button2.Image.Save(fs,
                                   System.Drawing.Imaging.ImageFormat.Bmp);
                                break;
        
                            case 3:
                                this.button2.Image.Save(fs,
                                   System.Drawing.Imaging.ImageFormat.Gif);
                                break;
                        }
        
                        fs.Close();
                    }*/
                    saveFileDialog1.Filter = "JPEG File (*.jpg)|*.jpg|Bitmap File (*.bmp)|*.bmp|PNG File(*.png)|*.png";
                    if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        switch (Path.GetExtension(saveFileDialog1.FileName))
                        {
                            case ".jpg":
                                pictureBox1.Image.Save(saveFileDialog1.FileName, ImageFormat.Jpeg); break;
                            case ".bmp":
                                pictureBox1.Image.Save(saveFileDialog1.FileName, ImageFormat.Bmp); break;
                            case ".png":
                                pictureBox1.Image.Save(saveFileDialog1.FileName, ImageFormat.Png); break;
                        }
                    }
                }
        
                private void button1_Click(object sender, EventArgs e)
                {
                    // Wrap the creation of the OpenFileDialog instance in a using statement,
                    // rather than manually calling the Dispose method to ensure proper disposal
                    using (OpenFileDialog dlg = new OpenFileDialog())
                    {
                        dlg.Title = "انتخاب عکس";
                        dlg.Filter = "bmp files (*.bmp)|*.bmp|JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif";
        
                        if (dlg.ShowDialog() == DialogResult.OK)
                        {
                           // PictureBox PictureBox1 = new PictureBox();
        
                            // Create a new Bitmap object from the picture file on disk,
                            // and assign that to the PictureBox.Image property
                            pictureBox1.Image = new Bitmap(dlg.FileName);
                        }
                    }
                }
            }
        when i want to save picture the open file dialog was opened and after get file name and path is save picture i want to select path before load open dialog and file name before that open.
        Last edited by Rabbit; Nov 26 '12, 09:14 PM. Reason: Please use code tags when posting code.

        Comment

        • Rabbit
          Recognized Expert MVP
          • Jan 2007
          • 12517

          #5
          Please use code tags when posting code.

          I thought this was for a website, which was why I mentioned the zip file. But apparently that is not the case.

          Instead, what you want to do is declare a global variable for the path and call the dialog only if it hasn't been populated yet.

          Comment

          Working...