Reputation: 317
How can I remove the extension file in asp.net something like filename.jpg
to filename
? I tried searching some reference but all I find is URL extension only
Upvotes: 0
Views: 1789
Reputation: 969
Use the System.IO.Path.GetFileNameWithoutExtension Method
The return value for this method is the string returned by GetFileName, minus the last period (.) and all characters following it.
string fileName = Path.GetFileNameWithoutExtension(fuImage.FileName); //file-name
string fileExt = Path.GetExtension(fuImage.FileName); //.jpg,.png....
string path_thumb = Path.Combine("Images/", string.Format("{0}{1}{2}", fileName, "-" + datetime + "-thumb", fileExt)); //full path: Images/file-name-012345-thumb.jpg
Upvotes: 1