Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Unexpected WPF Behaviour with Microsoft.Win32.OpenFileDialog [modified]

Unexpected WPF Behaviour with Microsoft.Win32.OpenFileDialog [modified]

Scheduled Pinned Locked Moved WPF
csharpwpfdesignquestion
3 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mitch F
    wrote on last edited by
    #1

    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

    P 1 Reply Last reply
    0
    • M Mitch F

      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

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      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.

      My blog | My articles

      M 1 Reply Last reply
      0
      • P Pete OHanlon

        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.

        My blog | My articles

        M Offline
        M Offline
        Mitch F
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups