Solved

Pulling a file extension

Posted on 2009-07-05
3
267 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 ITIL 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How come this regular expression allows "e"? 14 58
C# Windows app updating JSON file error. 9 39
pressing download button in c# 7 36
C# DataTable (in memory) vs SQL Lookups 4 36
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

733 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