Solved

filename without extension in VB.NET

Posted on 2004-08-24
6
844 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now