1

I'm having an issue with the OpenFileDialog class, where the OpenFileDialog window will open, but only behind every other application I have running in my OS. I've been hesitant to ask about this, but my search using many different keywords on Google, and searching other forums, has turned up nil. I'm using the following code in a button click event of the button on my web form I want the user to click on to open the file dialog:

Dim fd As New OpenFileDialog()
    Dim strFileName As String = ""
    fd.Title = "Open File Dialog"
    fd.InitialDirectory = "C:\"
    fd.Filter = "All files (*.*)|*.*|All files (*.*)|*.*"
    fd.FilterIndex = 2
    fd.RestoreDirectory = True

    If fd.ShowDialog = DialogResult.OK Then
        strFileName = fd.FileName
    End If

The dialog box opens - it just opens behind every other window...what am I missing here? Am I just going to have to do a funky workaround by minimizing everything when I call the OpenFileDialog class? All I need is for the window to show in front of the browser and every other window. Thanks in advance for your help!

Nate Major
  • 77
  • 1
  • 9
  • What does this have to do with ASP.NET? You are not openning a file dialog from code behind, are you? – Igor Jun 03 '13 at 20:00
  • Maybe this is fun - you open the dialog from the IIS ? on server side ? Similar to this: http://stackoverflow.com/questions/12342519/how-to-play-sound-by-clicking-button-in-asp-net/12342639#12342639 – Aristos Jun 03 '13 at 20:01
  • Igor - I am indeed opening a file dialog from code behind. If this isn't the best way of having a user upload a file using a web form, what is? – Nate Major Jun 03 '13 at 20:04
  • Search on the internet for the Upload Files. – Aristos Jun 03 '13 at 20:05
  • Thanks Aristos. Looks like the FileUpload control might be what I need. I have no idea why I was so bent on using OpenFileDialog, when that only works on the server side, as indicated by Igor -_-... – Nate Major Jun 03 '13 at 20:10

1 Answers1

2

openfiledialog has no place in a standard ASP.NET application. If you call ShowDialog on it, the dialog will open on the server computer (under what user session?) unbeknownst to user looking at the browser window on the client.

Use <input type="file" ... or FileUpload server control to let user select a file to be uploaded to the server.

Igor
  • 15,833
  • 1
  • 27
  • 32