modified the sample to handle the case when no file is selected.