Openfiledialog

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jaeden99
    New Member
    • May 2007
    • 19

    #1

    Openfiledialog

    When trying to use this control, how do you change the default filename, OPENFILEDIALOG1 is what is showing up in filename textbox? Any hint or clue to what I am doing incorrectly.

    Here is the code that I am using:

    With OpenFileDialog1
    .InitialDirecto ry = "C:"
    .Filter = "All Files (*.*)|*.*"
    .CheckFileExist s = True
    TextBox1.Text = (DataGridView1. SelectedCells(0 ).Value.ToStrin g())
    hit = TextBox1.Text
    'TextBox1.Text = (DataGridView1. SelectedCells(0 ).Value.ToStrin g())

    'open Dialiog
    If .ShowDialog = Windows.Forms.D ialogResult.OK Then
    'm_InputStream = CType(OpenFileD ialog1.OpenFile (), System.IO.Strea mReader)
    m_inputstream = New System.IO.Strea mReader(OpenFil eDialog1.OpenFi le)
    If m_inputstream Is Nothing Then
    Throw New Exception("Erro r opening the file")
    End If

    ' OpenFileDialog1 .ToString = hit


    End If
    End With
  • SammyB
    Recognized Expert Contributor
    • Mar 2007
    • 807

    #2
    .FileName
    Code:
    With OpenFileDialog1
    	 .InitialDirectory = "C:"
    	 .Filter = "All Files (*.*)|*.*"
    	 .CheckFileExists = True
    	 .FileName = "WORK.LOG"
    	 If .ShowDialog = Windows.Forms.DialogResult.OK Then
    		 MsgBox(.FileName)
    	 End If
    End With

    Comment

    • jaeden99
      New Member
      • May 2007
      • 19

      #3
      How do you get it the file to open? I can pull up the file dialog and the filename is the textbox, but when I click on open, nothing happens...at least I don't see anything happening.
      I would like to be able to view the actual document when I click on open.

      Any suggestions.
      It's like downloading an attachment and viewing it. But it is in a windows application instead of a web based. I know it probably would be easy in web.

      Comment

      • SammyB
        Recognized Expert Contributor
        • Mar 2007
        • 807

        #4
        LOL, the dialog only gives you the filename, it does not open, read, or write. You'll need to use StreamWriter and/or StreamReader. It's explained at http://support.microsoft.com/kb/304427. --Sam

        Comment

        • mwalts
          New Member
          • May 2007
          • 38

          #5
          Originally posted by SammyB
          LOL, the dialog only gives you the filename, it does not open, read, or write. You'll need to use StreamWriter and/or StreamReader. It's explained at http://support.microsoft.com/kb/304427. --Sam
          Right, also it seems to me that you may just want to open the file with whatever is the default application for that file type. If that is true, then you should look into the Process class (in the System.Diagnost ics namespace).

          Specifically with the StartInfo.UseSh ellExecute property set to true.
          Yes I could tell you exactly how to use it, but google it first, it'll be good practice

          Good luck,

          -mwalts

          Comment

          • SammyB
            Recognized Expert Contributor
            • Mar 2007
            • 807

            #6
            Also, I keep forgetting the the OpenFileDialog has a OpenFile method that returns a Stream object, http://msdn2.microsoft.com/en-us/lib....openfile.aspx

            Comment

            Working...