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.

Recommended Answers

All 5 Replies

remove FileExtension

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

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

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
commented: Thanks +9
ComboBox2.Items.Add(System.IO.Path.GetFileNameWithoutExtension(carrier.FullName))
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.