0

I have a listbox, I save it to a txt file with following code.

            String[] array = new String[listBox2.Items.Count];
            listBox2.Items.CopyTo(array, 0);
            Microsoft.Win32.SaveFileDialog saveFileDialog1 = new Microsoft.Win32.SaveFileDialog();

            saveFileDialog1.FileName = "per_" ;
            saveFileDialog1.DefaultExt = ".txt";
            saveFileDialog1.Filter = "Text files (.txt)|*.txt";

            Nullable<bool> res = saveFileDialog1.ShowDialog();

            if (res == true)
            {
                string filename = saveFileDialog1.FileName;

                File.WriteAllLines(filename, array, Encoding.UTF8);

                MessageBox.Show("File saved successfully");
            }

I save chart to c://

chart2.SaveImage("C://", System.Drawing.Imaging.ImageFormat.Jpeg);

However I want to save my chart at same direction which user chosed with savefiledialog. What should I do to manage this?

Mr_Green
  • 40,727
  • 45
  • 159
  • 271
Oktay
  • 127
  • 1
  • 2
  • 15

1 Answers1

0

Try this

chart2.SaveImage(Path.GetDirectoryName(saveFileDialog1.FileName), System.Drawing.Imaging.ImageFormat.Jpeg);

or this

chart2.SaveImage(Path.GetDirectoryName(saveFileDialog1.FileName) + "\\chart.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

if SaveImage method needs a filename

alfoks
  • 4,324
  • 4
  • 29
  • 44