Solved

Pulling a file extension

Posted on 2009-07-05
3
262 Views
Last Modified: 2012-05-07
In c# what is an easy way to find a file extension.

My current way is kinda messy, and is very easy for the user to mess up.

The exact thing required is for the program to go forward one file, and look at a file of extension *.F*  where the second star is a number 4-10

Any Suggestions?
0
Comment
Question by:cotj73
3 Comments
 
LVL 9

Accepted Solution

by:
Rahul Goel earned 175 total points
ID: 24782526
You can use RegEx to achieve the same.
0
 
LVL 1

Assisted Solution

by:vaibhav_dw
vaibhav_dw earned 175 total points
ID: 24782547
Hi

Are you trying to extract the extension from the filename as the string or you have the filestream?

If you have just the filename as the string then you can traverse the string backwords till the period(.) and then traverse extactly 3 characters to get the extension. This is simply playing with the string.

Could you please tell exactly what do you have as a file so that I can help you out.

0
 
LVL 7

Assisted Solution

by:Raghu Mutalikdesai
Raghu Mutalikdesai earned 150 total points
ID: 24783299
// path is your file path
System.IO.Path.GetExtension(path)
System.IO.Path.GetFileNameWithoutExtension(path)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

867 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

16 Experts available now in Live!

Get 1:1 Help Now