开发者

C#:Saving image to folder

HI. I know this is simple question but when I use

 FirstPersonTestImage.Save(IIdComboBox.Text + "-" + i + ".jpg");

it works and saves file to folder where is the .exe file . But I want to save it to specific folder like /photo/IO-66/ and tryed to use

 String StudentPath = PhotoPath + IGroupNoComboBox.Text + "/" + IIdComboBox.Text + "/" + IIdComboBox.Text + "-" + i + ".jpg";

 FirstPersonTestImage.Save(StudentPath);

BUt it gives

An unhandled exception of type 'System.Runtime.InteropServices.ExternalException' occurred in System.Drawing.dll

How can I solve this problem? Is is about folder path ? or using "/" ?

EDIT

Here My code for creating and checking exi开发者_开发知识库sting or not folder

  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() + "/");

            }


Instead of adding the path together manually, just use the IO.Path.Combine method and you don't have to worry about it.

If you're in VS2010 you can just call it with multiple parameters and otherwise you'll have to have nested calls.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜