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. C#
  4. Problem with Open Dialog box

Problem with Open Dialog box

Scheduled Pinned Locked Moved C#
databasehelp
2 Posts 2 Posters 0 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.
  • R Offline
    R Offline
    ranandbe
    wrote on last edited by
    #1

    Hi Folks, i have a problem with common dialog', I need to open a file when i click the item from listbox. now i got open dialog with specified path but it dont open the file. can you plz give idea to solve this. my code is here., the following code in selected index changed event for thet listbox. OpenDialog.FileName="Filepath"; OpenDialog.OpenFile(); OpenDialog.ShowDialog(); ranandbe

    L 1 Reply Last reply
    0
    • R ranandbe

      Hi Folks, i have a problem with common dialog', I need to open a file when i click the item from listbox. now i got open dialog with specified path but it dont open the file. can you plz give idea to solve this. my code is here., the following code in selected index changed event for thet listbox. OpenDialog.FileName="Filepath"; OpenDialog.OpenFile(); OpenDialog.ShowDialog(); ranandbe

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      ??? I don't understand your code and what do you want to do with that, but normally I use it like this:

      OpenFileDialog openFileDialog = new OpenFileDialog();
      DialogResult dialogResult = openFileDialog.ShowDialog();
      if(dialogResult == DialogResult.OK && openFileDialog.FileName != "")
      {
      // use something with this filename (openFileDialog.FileName)
      // For example :
      // FileStream fileStream = new FileStream(openFileDialog.FileName, FileMode.Open);
      // ...
      // fileStream.Close();
      }

      or

      OpenFileDialog openFileDialog = new OpenFileDialog();
      if(openFileDialog.ShowDialog() == DialogResult.OK)
      {
      System.IO.FileStream filestream = openFileDialog.OpenFile();
      // ... use something with filestream
      filestream.Close();
      }

      Before ShowDialog() you can only set the property like Path, Filter, etc... Then you must call ShowDialog() to show the dialog. If the user select a file and click OK, then you get a return value DialogResult.OK. Then you can get the filename by calling openFileDialog.FileName.

      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