HI。我知道这是一个简单的问题,但当我使用C#:将图像保存到文件夹
FirstPersonTestImage.Save(IIdComboBox.Text + "-" + i + ".jpg");
它的工作原理并将文件保存到.exe文件所在的文件夹。但我想将其保存到特定的文件夹如/照片/ IO-66 /和tryed使用
String StudentPath = PhotoPath + IGroupNoComboBox.Text + "/" + IIdComboBox.Text + "/" + IIdComboBox.Text + "-" + i + ".jpg";
FirstPersonTestImage.Save(StudentPath);
但它给
An unhandled exception of type 'System.Runtime.InteropServices.ExternalException' occurred in System.Drawing.dll
我怎样才能解决这个问题?是关于文件夹路径吗?或使用“/”?
编辑
这里我创建和检查现有的或不代码文件夹
if (!System.IO.Directory.Exists(PhotoPath + "/" + IGroupNoComboBox.Text.ToString().Trim()))
{
Directory.CreateDirectory(PhotoPath + "/" + IGroupNoComboBox.Text.ToString().Trim());
}
if (!System.IO.Directory.Exists(PhotoPath + "/" + IGroupNoComboBox.Text.ToString().Trim()+ "/" + IIdComboBox.Text.ToString().Trim() + "/"))
{
Directory.CreateDirectory(PhotoPath + "/" + IGroupNoComboBox.Text.ToString().Trim()+"/" + IIdComboBox.Text.ToString().Trim() + "/");
}
你可以检查出来,只需使用调试器 – thelost 2010-06-02 11:46:42
使用'Path.Combine()'或用''替换'“/”'''\\“' – Oliver 2010-06-02 11:52:05
arrgh!恶梦。为什么你不创建路径一次,并将其分配给一个变量,然后使用它? – 2010-06-02 11:55:00