Results 1 to 8 of 8

Thread: totally at a loss with openfiledialog extension

  1. #1

    Thread Starter
    Registered User jkw119's Avatar
    Join Date
    Oct 2001
    Location
    Pittsburgh
    Posts
    256

    totally at a loss with openfiledialog extension

    i have the following code

    VB Code:
    1. Dim myStream As System.IO.Stream
    2. Dim openFileDialog1 As New OpenFileDialog()
    3.  
    4. openFileDialog1.Title = "Open a File"
    5. openFileDialog1.InitialDirectory = "c:\"
    6. openFileDialog1.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*"
    7. openFileDialog1.FilterIndex = 1
    8. openFileDialog1.RestoreDirectory = True
    9.  
    10. If openFileDialog1.ShowDialog() = DialogResult.OK Then
    11.             myStream = openFileDialog1.OpenFile()
    12.             fileName = openFileDialog1.FileName
    13.             MsgBox(fileName)
    14.             If Not (myStream Is Nothing) Then
    15.                 myStream.Close()
    16.             End If
    17. End If

    the thing that gets me, is that when i display the string name "filename" in the message box, it has two extension,

    "test.xml.xml"

    how can i only make it add one extension... I have no idea what is wrong..

    thanks,

    jeff

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    I dont know what you are doing wrong, cause I tried the code it worked ok.

    BTW what do you have fileName declared as?

    I declared it as a string and it worked perfect.

    Hope that helped

  3. #3
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Did you name your files with the extension? I know that sounds stupid but if you name a text file Text.txt.txt you will get two extensions. I can't see either why your code would do that since the first part of the filter is just a description of the file type.
    Try changing the first part of the filter just to see. ie......
    Code:
    OpenFileDialog.Filter = "TextFiles|*.txt|AllFiles| *.*|ExcelFiles|*.xls"

  4. #4
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    Could it be that you have set the option to hide extensions for known filetypes in explorer?
    Maybe the file really is named test.xml.xml, and explorer hides the extension so it looks like it is named test.xml

  5. #5

    Thread Starter
    Registered User jkw119's Avatar
    Join Date
    Oct 2001
    Location
    Pittsburgh
    Posts
    256
    i did name the file with two extensions, i must have not got enough sleep yesterday. the code works perfect...

    thanks,

    jeff

  6. #6
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    jkw deserves a kick in the butt


    You get a big D'uh

    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  7. #7

  8. #8
    Lively Member
    Join Date
    Jun 2002
    Location
    Coming to a keyboard near you.
    Posts
    79
    Answered m own question. hahahaha
    Last edited by Tenebrosity; Jul 10th, 2003 at 08:32 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width