So I am making a program and in the program I give the user the option to add Custom Items into the Combobox. To make sure that the Custom Items are still there when the program is restarted I use this code in the form load

Dim customcarrier As New IO.DirectoryInfo(Application.StartupPath & "\CUSTOM\")
        Dim carriers As IO.FileInfo() = customcarrier.GetFiles("*.txt")'gets all the custom items in the directory
        Dim carrier As IO.FileInfo
        For Each carrier In carriers
            ComboBox2.Items.Add(carrier)'adds filename into textbox
        Next

The problem is that the program adds the whole filename with the extension to the Combobox. Is there any way I can exempt the last 4 char (.txt)

Srry if I am unclear describing is always hard for me.

remove FileExtension

filename=System.IO.Path.GetFileNameWithoutExtension(path)

Edited 3 Years Ago by mike_2000_17: Fixed formatting

remove FileExtension

filename=System.IO.Path.GetFileNameWithoutExtension(path)

How would i implment tihs because I have tried and I get an error saying

Error   1   Value of type 'String' cannot be converted to 'System.IO.FileInfo'. C:\Documents and Settings\HP_Administrator\My Documents\Visual Studio 2008\Projects\Winapp1\winapp1\Form1.vb

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Use this code:

For Each carrier In carriers
[B] Dim fileName as String = IO.Path.GetFileNameWithoutExtension(carrier.FullName)[/B]
 ComboBox2.Items.Add([B]fileName[/B])'adds filename into textbox
Next

Edited 6 Years Ago by farooqaaa: n/a

Comments
Thanks
This question has already been answered. Start a new discussion instead.