tags:

views:

274

answers:

1

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

            }
+2  A: 

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.

ho1
Should I use Combine like IO.Path.Combine(PhotoPath,IGroupNoComboBox.Text + "/" + IIdComboBox.Text + "/" + IIdComboBox.Text + "-" + i + ".jpg") ?
Meko
Press F1 for help or see Code Insight tooltip...
Thorsten Dittmar
`Combine` glues together different directories, so whenever you use / you can use `Combine` to combine them instead, you'll still have to create the filename manually as you currently do. As Thorsten says, look at the help - http://msdn.microsoft.com/en-us/library/dd991142.aspx
ho1
I used Path.Combine and it does not worked and i release that instead of " - " ,I should use " _ " . And then worked. Also with out Path.Combine works too , but less mess is every time good ))
Meko