Truemag

  • Categories
    • Tips And Tricks
    • Internet
    • PHP
    • Javascript
    • CSharp
    • SQL Server
    • Linux
  • Lastest Videos
  • Our Demos
  • About
  • Contact
  • Home
  • Write With Us
  • Job Request
Home CSharp C# Get File Extension Without Sub String Or Split Function

C# Get File Extension Without Sub String Or Split Function

In many cases of file manipulation or validation, you will need to get the file name, file name without extension and especially with file extension when check an uploaded file on the fly or scan your project files.

By using the System.IO namespace, we don’t need to program to parse the string of file name or use any kind of substring or split function. The Path class in the namespace has 3 functions: GetExtension(), GetFileName(), GetFileNameWithoutExtension() to do that quickly and save a lot of time for you.

1. C# Get File Extension

string ext = System.IO.Path.GetExtension(Server.MapPath("members.xls"));
Response.Write("ext: " + ext + "<br>"); // .xls

string ext = System.IO.Path.GetExtension(Server.MapPath("members.xls")); Response.Write("ext: " + ext + "<br>"); // .xls

2. C# Get File Name

string ext = System.IO.Path.GetFileName(Server.MapPath("members.xls"));
Response.Write("file name: " + file_name+ "<br>"); // members.xls

string ext = System.IO.Path.GetFileName(Server.MapPath("members.xls")); Response.Write("file name: " + file_name+ "<br>"); // members.xls

3. C# Get File Name Without Extension

string ext = System.IO.Path.GetFileNameWithoutExtension(Server.MapPath("members.xls"));
Response.Write("file name without extension: " + file_name_without_extension+ "<br>"); // members

string ext = System.IO.Path.GetFileNameWithoutExtension(Server.MapPath("members.xls")); Response.Write("file name without extension: " + file_name_without_extension+ "<br>"); // members

Dec 3, 2011Hoan Huynh
C# Save Web Page URL To ImageC# Check File Extension In Array Of Valid Extension
You Might Also Like:
  • C# Check File Extension In Array Of Valid Extension
  • MSSQL Split String Function
  • Most Popular Video And Photo File Extension
  • C# Read File Content
  • Get Or Read AppSettings Item Value From The Web.Config File
  • MSSQL Split Function returns table data
  • ASP.Net C# Download Or Save Image File From URL
  • String To Lower Case In PHP, JavaScript And .Net (CSharp)
  • PHP Save String Content To File
  • Get File Mime Type Using PHP
Hoan Huynh

Hoan Huynh is the founder and head of 4rapiddev.com. Reach him at [email protected]

9 years ago CSharpGetExtension, GetFileName, GetFileNameWithoutExtension, MapPath, split, substring562
0
GooglePlus
0
Facebook
0
Twitter
0
Digg
0
Delicious
0
Stumbleupon
0
Linkedin
0
Pinterest
Most Viewed
PHP Download Image Or File From URL
22,209 views
Notepad Plus Plus Compare Plugin
How To Install Compare Text Plugin In Notepad Plus Plus
20,077 views
Microsoft SQL Server 2008 Attach Remove Log
Delete, Shrink, Eliminate Transaction Log .LDF File
15,854 views
JQuery Allow only numeric characters or only alphabet characters in textbox
13,334 views
C# Read Json From URL And Parse/Deserialize Json
9,828 views
4 Rapid Development is a central page that is targeted at newbie and professional programmers, database administrators, system admin, web masters and bloggers.
Recent Posts
  • Photo Editor App – How Good Is it?

  • The Best Way To Write An Essay – Creating A Good Essay
  • Free Online Photo Editor
  • Easy Tips For Writing An Essay
  • What Can I Expect From An Academic Essay Service?

Categories
  • CSharp (45)
  • Facebook Graph API (19)
  • Google API (7)
  • Internet (87)
  • iPhone XCode (8)
  • Javascript (35)
  • Linux (28)
  • MySQL (16)
  • PHP (84)
  • Problem Issue Error (29)
  • Resources (32)
  • SQL Server (25)
  • Timeline (5)
  • Tips And Tricks (141)
  • Uncategorized (114)
Recommended
  • Custom Software Development Company
  • Online Useful Tools
  • Premium Themes
  • VPS
2014 © 4 Rapid Development