Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 109,372 VB.NET Programmers for FREE! Ask your question and get quick answers from experts. There are 950 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! 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
post 21 Jul, 2008 - 06:16 PM
Post #1


New D.I.C Head

*
Joined: 8 Jun, 2008
Posts: 31

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 - 06:21 PM
User is offlineProfile CardPM

Go to the top of the page


PsychoCoder
post 21 Jul, 2008 - 06:32 PM
Post #2


DIC.Rules == true;

Group Icon
Joined: 26 Jul, 2007
Posts: 7,241



Thanked 52 times

Dream Kudos: 7775

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, GDI, Boo.Net

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

Go to the top of the page

bellaelysium
post 21 Jul, 2008 - 08:18 PM
Post #3


New D.I.C Head

*
Joined: 8 Jun, 2008
Posts: 31

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

Go to the top of the page

danny_kay1710
post 22 Jul, 2008 - 03:43 AM
Post #4


New D.I.C Head

*
Joined: 27 Apr, 2008
Posts: 17



Thanked 1 times
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 - 03:43 AM
User is offlineProfile CardPM

Go to the top of the page

bellaelysium
post 22 Jul, 2008 - 04:48 AM
Post #5


New D.I.C Head

*
Joined: 8 Jun, 2008
Posts: 31

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

Go to the top of the page

danny_kay1710
post 24 Jul, 2008 - 05:39 AM
Post #6


New D.I.C Head

*
Joined: 27 Apr, 2008
Posts: 17



Thanked 1 times
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

Go to the top of the page

bellaelysium
post 24 Jul, 2008 - 07:52 AM
Post #7


New D.I.C Head

*
Joined: 8 Jun, 2008
Posts: 31

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

Go to the top of the page

st0ne2thedge
post 24 Jul, 2008 - 11:40 AM
Post #8


New D.I.C Head

*
Joined: 23 Jul, 2008
Posts: 3

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

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 9/6/08 11:25PM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month