closet geek Posted April 4, 2006 Posted April 4, 2006 Hi, I have a tabbed application, when a user opens a file to be displayed in a tab I naturally want the filename to appear in the tab. Using this: openFileDialog1.get_FileName() Puts the whole path in the tab, making the tab very long e.g. C:/path/to/file.txt I just want: file.txt To be in the tab. How do I go about doing that? Thanks. Quote
kentheprogger Posted April 4, 2006 Posted April 4, 2006 Hi, I have a tabbed application, when a user opens a file to be displayed in a tab I naturally want the filename to appear in the tab. Using this: openFileDialog1.get_FileName() Puts the whole path in the tab, making the tab very long e.g. C:/path/to/file.txt I just want: file.txt To be in the tab. How do I go about doing that? Thanks. dim stringBuffer() as String stringBuffer = split("C:/path/to/file.txt", "/") fileName = stringBuffer(ubound(stringBuffer)) Quote
Cags Posted April 4, 2006 Posted April 4, 2006 dim path as string = "C:/path/to/file.txt" System.IO.Path.GetFileName(path) This way it will work regardless of whether the path uses "\"'s or "/"'s. Quote Anybody looking for a graduate programmer (Midlands, England)?
kentheprogger Posted April 4, 2006 Posted April 4, 2006 Thanks, now I can stop messing around with that split statement for this. =p Quote
ehelin Posted April 4, 2006 Posted April 4, 2006 Old way... Hi: I to try to use the GetFileName methods like the other posters suggested...however, I sometimes do the following: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim Path As String Dim Pos As Integer Path = "C:\FilePath\ReallyLong\LotsofDirectories\Practice\ScratchPad\bin\testing.bmp" Pos = Path.LastIndexOf("\") Path = Path.Substring(Pos + 1, Path.Length - (Pos + 1)) 'return file name MsgBox(Path) End Sub Quote
closet geek Posted April 4, 2006 Author Posted April 4, 2006 Thanks to everyone I've got it working now! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.