Click here to Skip to main content
Click here to Skip to main content

Tagged as

Ensure extension of file name is of your choice

, 24 Mar 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
There are cases where we want to ensure that the filename entered by the user has a valid extension of your choice, say .XLS, .ZIP. Sometimes user may not enter extension, or may enter wrong extension like .XLA, .ZIL. In such cases, here is a simple tip where we need not check how user enters...
There are cases where we want to ensure that the filename entered by the user has a valid extension of your choice, say .XLS, .ZIP. Sometimes user may not enter extension, or may enter wrong extension like .XLA, .ZIL. In such cases, here is a simple tip where we need not check how user enters the file name.
 
string orgFileName1 = @"d:\test\abc.xla";
string orgFileName2 = @"d:\test\abc";
 
string newFileName1 = System.IO.Path.ChangeExtension(orgFilename1, "xls");
string newFileName2 = System.IO.Path.ChangeExtension(orgFilename2, "xls");
 
//both newFileName1 and newFileName2 will hold d:\test\abc.xls
Console.WriteLine(newFileName1);
Console.WriteLine(newFileName2);

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Ravi LVS

India India
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141223.1 | Last Updated 24 Mar 2010
Article Copyright 2010 by Ravi LVS
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid