Click here to Skip to main content
15,945,119 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
in JavaScript
how to get the file name without extension, taking into consideration that a file name may contain dots.
ex: file.name.txt -> returns: file.name
Posted
Updated 12-Dec-17 21:22pm

Use FileInfo , follow the below code

in C#
FileInfo fno = new FileInfo("c:\\x.name.txt");
         MessageBox.Show(fno.Name.Replace(fno.Extension, ""));


for Java Script

link
http://stackoverflow.com/questions/680929/how-to-extract-extension-from-filename-string-in-javascript[^]
 
Share this answer
 
v2
Comments
Rojeh 21-Dec-11 4:09am    
is it in javascript??!
Rajesh Anuhya 21-Dec-11 4:11am    
ohhh., am sorry this is in C#, wait i will update it.
Rojeh 21-Dec-11 4:28am    
i checked this link before, it gets the extension not the file name.
anw 10x and it is done (i posted the solution)
Rojeh 21-Dec-11 5:50am    
my +5 for the c# solution
i used

var name = file.substr(0, file.lastIndexOf('.'));
 
Share this answer
 
v2
yes. it's easy.
try out following javacscript function
JavaScript
function getFileNameOnly()
{
  var fileName = document.getElementById("txtFileName").value; //get file name
  var ext = fileName.substr(fileName.lastIndexOf('.') + 1); 
}
 
Share this answer
 
Comments
Rojeh 21-Dec-11 4:28am    
i guess +1 will return the dot

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900