我有listbox
,我将其保存为包含以下代码的txt文件。
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");
}
我将图表保存到c://
chart2.SaveImage("C://", System.Drawing.Imaging.ImageFormat.Jpeg);
但是我想将我的图表保存在与savefiledialog
选择的用户相同的方向上。我应该怎么做才能解决这个问题?
答案 0 :(得分:0)
试试这个
chart2.SaveImage(Path.GetDirectoryName(saveFileDialog1.FileName), System.Drawing.Imaging.ImageFormat.Jpeg);
或者
chart2.SaveImage(Path.GetDirectoryName(saveFileDialog1.FileName) + "\\chart.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
如果SaveImage方法需要文件名