Unexpected WPF Behaviour with Microsoft.Win32.OpenFileDialog [modified]
-
I've come across some really unexpected behavior using the OpenFileDialog, WPF, and a PocketPC (physical) device. I'm trying to let users select a file on their PocketPC using an OpenFileDialog, and when the user selects Open, WPF copies the file into the Temporary Internet Files directory, and then returns that as the path. I'm really confused as to why this happens, but here's the code to reproduce it.
Dim ofd As New Microsoft.Win32.OpenFileDialog ofd.CheckFileExists = False ofd.CheckPathExists = True ofd.AddExtension = False ofd.Filter = "Folders|\*.\*" ofd.Multiselect = False ofd.InitialDirectory = "C:\\" ofd.ShowDialog() Console.WriteLine(ofd.FileName)
When I select a file from the My Documents (eg, "\My Documents\Meeting Notes.psw") directory on my PocketPC, this is the output that is written in the console "C:\Users\*****\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5\82P6MGLK\Meeting_Notes[1].psw" (Note, the astericks are used to hide my user-name). In addition to this, if you try it with a large file, the UI just freezes until the file finishes copying. Windows does not say that the program is "Not Responding", just you can't interact with the UI at all. Does anyone know why this happens? It certainly is interesting behaviour. Thanks, Mitch
modified on Thursday, June 12, 2008 1:11 AM
-
I've come across some really unexpected behavior using the OpenFileDialog, WPF, and a PocketPC (physical) device. I'm trying to let users select a file on their PocketPC using an OpenFileDialog, and when the user selects Open, WPF copies the file into the Temporary Internet Files directory, and then returns that as the path. I'm really confused as to why this happens, but here's the code to reproduce it.
Dim ofd As New Microsoft.Win32.OpenFileDialog ofd.CheckFileExists = False ofd.CheckPathExists = True ofd.AddExtension = False ofd.Filter = "Folders|\*.\*" ofd.Multiselect = False ofd.InitialDirectory = "C:\\" ofd.ShowDialog() Console.WriteLine(ofd.FileName)
When I select a file from the My Documents (eg, "\My Documents\Meeting Notes.psw") directory on my PocketPC, this is the output that is written in the console "C:\Users\*****\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5\82P6MGLK\Meeting_Notes[1].psw" (Note, the astericks are used to hide my user-name). In addition to this, if you try it with a large file, the UI just freezes until the file finishes copying. Windows does not say that the program is "Not Responding", just you can't interact with the UI at all. Does anyone know why this happens? It certainly is interesting behaviour. Thanks, Mitch
modified on Thursday, June 12, 2008 1:11 AM
It'll be the same behaviour as with a Windows Forms app. It sounds like you are performing the copy on the primary thread, which blocks the UI until it completes the operation. Try moving the copy onto a background thread instead - this should help.
Deja View - the feeling that you've seen this post before.
-
It'll be the same behaviour as with a Windows Forms app. It sounds like you are performing the copy on the primary thread, which blocks the UI until it completes the operation. Try moving the copy onto a background thread instead - this should help.
Deja View - the feeling that you've seen this post before.
Pete O'Hanlon wrote:
It'll be the same behaviour as with a Windows Forms app.
I just tried the same block of code in .Net 2.0, and that's correct; it copied the file to my hard drive as well.
Pete O'Hanlon wrote:
It sounds like you are performing the copy on the primary thread, which blocks the UI until it completes the operation.
The only thing that confuses me is that I don't have any code to perform the copy in my project; when the user presses the Open button on the OpenFileDialog, it is copied over automatically without any extra code. Thanks, Mitch