Click here to Skip to main content
15,894,460 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I was at first wonding if it was possible to display the first line of text only in my text file to a label but thought it may be easier to display the name of the file itself eg. 123.txt without the file extention so it just reads 123

is there an easy way to do this?
:p...
Posted

1 solution

You may use the GetFilenameWithoutExtension of the Path class[^] , for instance

VB
Imports System.IO
  Module Module1
  Sub Main()
    Dim mypath As String = "c:\temp\123.txt"
    Dim myfilename = Path.GetFileNameWithoutExtension(mypath)
    Console.WriteLine(myfilename)
  End Sub
 
Share this answer
 
Comments
Dalek Dave 7-Dec-10 4:01am    
Good Answer.
CPallini 7-Dec-10 4:13am    
@Dave: Why thank you, man.
Dale 2012 7-Dec-10 9:31am    
Good man thank you very much for this
CPallini 7-Dec-10 9:33am    
@Dale: you are welcome.
Dale 2012 8-Dec-10 12:11pm    
Instead of displaying in console how can you display it in a label?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900