Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

file path name

Hi:
   I need to add selected filenames to an array. My code currently is below:. Apparently LoadFileName is not thecorrect method name to use. Is there a method i can call to add the entire path name of the current file to an String array.
Thanx
Dim o As New OpenFileDialog

        o.Title = "Select the file to open"
        o.Filter = "Text file|*.txt|Rich text file|*.rtf"
        o.InitialDirectory = "c:\temp"
        If o.ShowDialog = DialogResult.OK Then
            If o.FileName <> "" Then
                Select Case o.FilterIndex
                    Case 1
                        rtxtFiles.LoadFileName(o.FileName, RichTextBoxStreamType.PlainText)
                    Case 2
                        rtxtFiles.LoadFileName(o.FileName, RichTextBoxStreamType.RichText)
                End Select
            End If
        End If
        o.Dispose()
        o = Nothing
0
LuckyLucks
Asked:
LuckyLucks
  • 3
  • 3
  • 2
  • +1
1 Solution
 
iboutchkineCommented:
what about
GetFileName(o.FileName)
0
 
Bob LearnedCommented:
RichTextBox.LoadFile(path)

Bob
0
 
iboutchkineCommented:
Hi Bob, as I understood, the asker does not need to load file to the rtb, but load the path
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Bob LearnedCommented:
Hello, Iouri, I read that LoadFileName was not a member of what appears to be a RichTextBox, and the right method is LoadFile.

But, as always, I could be wrong :(

Bob
0
 
LuckyLucksAuthor Commented:
FileName gives the entire file path along with the name. How would that be cropped to just the file's name? PS: I know LoadFileName doesnt exists and LoadFile is the correct version but thats not related to the end result I am trying to get.
0
 
Bob LearnedCommented:
So, you're right Iouri.  It would be LoadFile(System.IO.GetFileName(o.FileName)).

I am outta here.

Bob
0
 
LuckyLucksAuthor Commented:
hey
   how about cropping the entire pathname to just the file's name??
0
 
iboutchkineCommented:
that is how to extract file name

If Me.OpenFileDialog1.ShowDialog() = DialogResult.OK Then
    ' The below line retrieves the last index of "\"
    Dim Get_Last_Slash As Integer
    Get_Last_Slash = Me.OpenFileDialog1.FileName.LastIndexOf("\")
    ' Use the Get_Last_Slash to strip the path from the filename and get only the filename
     MsgBox(Me.OpenFileDialog1.FileName.Remove(0, Get_Last_Slash + 1))
End
0
 
wyoung76Commented:
Or, to extend on iboutchkine's example, you could use the System.IO.Path.GetFileNameWithoutExtension function:

MsgBox(System.IO.Path.GetFileNameWithoutExtension(Me.OpenFileDialog1.FileName)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now