Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everybody!
I've got a database file (.xml), and i've got a written path in the program code
public static string FilePath = @"c:\Users\DamiRocK\Desktop\EShop\EShopWinApp\EShopData\DB.xml";

And when i send my prog to the other machine, or i put it in other folder, of course, program send the exception, that file could not be found.
So i wanna ask, if it's possible to catch this exception and allow user to select DB.xml manually through the browse-file window?
Posted

1 solution

Of course...but there are two parts to this.

First, you should really be using user settings because with your current approach you will have to prompt the user every run.

Secondly, if you want to go ahead with this, you'll need to wrap you file opening with a try...catch and then catch the FileNotFoundException. In that catch block, allow the user to select a file (or branch out to another method with it's own try...catch block so you can trap further errors).

You can use the standard file dialog for the user to select a file, and grab the filename from the control when the dialog is closed.

Cheers,
-jc
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900