Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 244,533 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,367 people online right now. Registration is fast and FREE... Join Now!




[VB2005]how do I remove file extension in listbox?

 
Reply to this topicStart new topic

[VB2005]how do I remove file extension in listbox?, To prevent it from showing in listbox

bellaelysium
21 Jul, 2008 - 05:16 PM
Post #1

New D.I.C Head
*

Joined: 8 Jun, 2008
Posts: 32



Thanked: 1 times
My Contributions
I have this code where I was able to display files in listbox from open file dialog box.

here's part of it:
CODE
If .ShowDialog() = System.Windows.Forms.DialogResult.OK Then        
                For Each file As String In .FileNames  'Loop through the file names

                  Listbox1.Items.Add(file)  'Add files to list box



How do I add this line

CODE
  ' newfile = System.IO.Path.GetFileNameWithoutExtension(file)


to prevent listbox from displaying file extension, while its full path is still there for me to open the files ?



Many thanks if theres someone who can guide me. smile.gif

This post has been edited by bellaelysium: 21 Jul, 2008 - 05:21 PM

User is offlineProfile CardPM
+Quote Post


PsychoCoder
RE: [VB2005]how Do I Remove File Extension In Listbox?
21 Jul, 2008 - 05:32 PM
Post #2

loves.Coding(this);
Group Icon

Joined: 26 Jul, 2007
Posts: 12,327



Thanked: 376 times
Dream Kudos: 10800
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

My Contributions
Try this


vb

Listbox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(file)) 'Add files to list box


But be aware, if the extension isn't on the file then your system cannot open it (because it's cant guess what type of file it is)
User is offlineProfile CardPM
+Quote Post

bellaelysium
RE: [VB2005]how Do I Remove File Extension In Listbox?
21 Jul, 2008 - 07:18 PM
Post #3

New D.I.C Head
*

Joined: 8 Jun, 2008
Posts: 32



Thanked: 1 times
My Contributions
hi thanks:)

Oh..opening of files, I just add

CODE
fullpath = System.IO.Path.GetFullPath(selectedfile)


when I want to open the files.
(more of trial and error but surprisingly, it works)
User is offlineProfile CardPM
+Quote Post

danny_kay1710
RE: [VB2005]how Do I Remove File Extension In Listbox?
22 Jul, 2008 - 02:43 AM
Post #4

D.I.C Head
Group Icon

Joined: 27 Apr, 2008
Posts: 153



Thanked: 10 times
Dream Kudos: 50
My Contributions
That could work where there is only one possibility.

It COULD get confused if you say had two or more files with the same name without extension. Say you had a setup.exe, setup.inf and setup.bmp file which extension is the app gonna add on the end to run??

This post has been edited by danny_kay1710: 22 Jul, 2008 - 02:43 AM
User is offlineProfile CardPM
+Quote Post

bellaelysium
RE: [VB2005]how Do I Remove File Extension In Listbox?
22 Jul, 2008 - 03:48 AM
Post #5

New D.I.C Head
*

Joined: 8 Jun, 2008
Posts: 32



Thanked: 1 times
My Contributions
QUOTE(danny_kay1710 @ 22 Jul, 2008 - 03:43 AM) *

That could work where there is only one possibility.

It COULD get confused if you say had two or more files with the same name without extension. Say you had a setup.exe, setup.inf and setup.bmp file which extension is the app gonna add on the end to run??


so by adding this :
CODE
fullpath = System.IO.Path.GetFullPath(selectedfile)


It will be alright right?
Cos it will give full path of filenames.

User is offlineProfile CardPM
+Quote Post

danny_kay1710
RE: [VB2005]how Do I Remove File Extension In Listbox?
24 Jul, 2008 - 04:39 AM
Post #6

D.I.C Head
Group Icon

Joined: 27 Apr, 2008
Posts: 153



Thanked: 10 times
Dream Kudos: 50
My Contributions
QUOTE(bellaelysium @ 22 Jul, 2008 - 04:48 AM) *


so by adding this :
CODE
fullpath = System.IO.Path.GetFullPath(selectedfile)


It will be alright right?
Cos it will give full path of filenames.



Personally I think you could hit problems.

Say you have three entries in the list box which are

c:\setup
c:\setup
c:\setup

These are setup.bmp, setup.exe and setup.inf respectively.

Thats all good - until you click one of them. The user wants to run setup.exe. Firstly he doesn't know which one that is. You could make the assumption it would be the second one as the chances are it would be alphabetic. But when you run the code:

CODE
fullpath = System.IO.Path.GetFullPath(selectedfile)


It could return any of the three files mentioned.

Do you get what I mean it's kind of hard to explain.

Danny
User is offlineProfile CardPM
+Quote Post

bellaelysium
RE: [VB2005]how Do I Remove File Extension In Listbox?
24 Jul, 2008 - 06:52 AM
Post #7

New D.I.C Head
*

Joined: 8 Jun, 2008
Posts: 32



Thanked: 1 times
My Contributions
hello.

Yes. I get what you mean.

But I dun think that will be a problem in my case, as my project involves opening only text files, and I have use filter for open file dialog to open text files only. smile.gif

Thanks for the tip btw smile.gif
User is offlineProfile CardPM
+Quote Post

st0ne2thedge
RE: [VB2005]how Do I Remove File Extension In Listbox?
24 Jul, 2008 - 10:40 AM
Post #8

New D.I.C Head
*

Joined: 23 Jul, 2008
Posts: 7

QUOTE(bellaelysium @ 24 Jul, 2008 - 07:52 AM) *

hello.

Yes. I get what you mean.

But I dun think that will be a problem in my case, as my project involves opening only text files, and I have use filter for open file dialog to open text files only. smile.gif

Thanks for the tip btw smile.gif

if you would want to avoid the problem i think you can set the exact value with the extention within an array, and instead of directly acting from the listbox, you simply use the listbox as a link to the real filename in the array with the
matching index.
This way you can avoid the multiple value problem
i guess :s

El Vino
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 7/5/09 11:57AM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month