Search code examples
.netwpfopenfiledialog

Error when using WPF OpenFileDialog more than once


In my wpf application I need a button which lets me select a file from my local system and upload it.
When I click the button for the first time and upload there is no problem; from the second onwards, there is this pop-up message box which displays

You can’t open this location using this program.
Please try a different location. openfiledialog

I can close that message and select my file.
But why is this appearing anyway?


Solution

  • I am passing a string to the initialdirectory property which has the lastopenenddfile's path. hence the directory is trying to open the file and hence showing the above message. I truncated the filepath to get the folder path and assigned it to the initialdirectory. Now working fine..