Solved

filename without extension in VB.NET

Posted on 2004-08-24
6
894 Views
Last Modified: 2008-01-09
Hi

i am having filename as "countrylist____23456.html"

1) i want to extract Only the file Name (NOT Extension)
2)and from the filename for eg.here "countrylist____23456",extract last 5 characters,
in this case "23456"


thanks for your reply

regards
0
Comment
Question by:vihar123
6 Comments
 
LVL 3

Expert Comment

by:imu79
ID: 11883129
you could do something like:

dim oFileInfo as New System.IO.FileInfo("countrylist____23456.html")
debug.WriteLine(oFileInfo.Name)

I'm not sure if the above prints the extension as well.
If it does, you can trim out the extension since the property oFileInfo.Extension gives you the extension string.

hope this helps..
Imran

0
 

Author Comment

by:vihar123
ID: 11883150
oFileInfo.Name prints filename with extension . "countrylist____23456.html"

0
 
LVL 19

Accepted Solution

by:
Desp earned 500 total points
ID: 11883180
       Dim f As New FileInfo("C:\countrylist____23456.html")
        Dim FName As String = f.Name.Substring(0, f.Name.LastIndexOf("."))
        FName = FName.Substring(FName.Length - 5, 5)
        MessageBox.Show(FName)
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11883289
or

        Dim oFileInfo As New System.IO.FileInfo("c:\C:\countrylist____23456.html")
        Dim g As String = oFileInfo.Name
        g = g.Replace(oFileInfo.Extension.ToString, "")
        g = g.Substring(g.Length - 5)
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11883338
hi there... use System.IO.Path

        MsgBox(System.IO.Path.GetFileNameWithoutExtension("C:\MyDoc01.doc"))

-Baan
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11883800
guess , you don't like single line code ...  :(
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.net Open Folder in Windows Explorer 3 50
Help with exporting to excel 4 35
Open a link in vb.net 2 15
Access/Visual Basic Question 3 24
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question