0

enter image description herei want to save to save a selected file in a specific folder. For that, i used a normal FileDialog. Additional, the main aim is that the opened file which will be open with this FileDialog, must be saved automatically in the chosen folder. But i get a System.IO.Exception which says that the directory name is invalid.

Can you help me to find out where is the problem ? I guess that there is a problem with my code statement.. Do you have any ideas or other suggestions for writing such a code ? The code

1 Answers1

0

Update

I just found this Semicolon at end of 'if' statement. It says having the semi-colon after your if statment will make it not act as an if statement basically. Read it and remove that semi colon too!

Original Answer

Modify your code to explicitly get the directory name and check if the directory exists before trying to use it. You can do this using new File("<path>") and checking that with .exists() and .isDirectory().

You can create the directory with .mkdirs() as well if it isn't there so that you can copy files into it after that.

This will help you spot errors in your name as well. I suspect your path is probably just bad / malformed. I'd log it out before the checks to make it more obvious.

John Humphreys
  • 37,047
  • 37
  • 155
  • 255