Set file with no .extension
I'm using the following code to trim the file extensions of some items . It latter pulls off a database. It seems database is not pulling the ".". In short I want file.ext to be turned to file but the closest Ive gotten is file "." which isn't working for me
string linkWithoutExtension = System.IO.Path.ChangeExtension(path, "");
Thanks for any help.
Edit Ok I changed it to the following but now its giving me an even weirder problem. Its renaming the path. So instead of it being (site.com/type/subtype/type1/video/videoname.) like I got before I now get (site.com/type/subtype/elsewhere/nothere/videoname).
开发者_运维问答string linkWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(path);
There's a Path.GetFileNameWithoutExtension
method so
string path = @"C:\Users\UN\Documents\message.msg";
string linkWithoutExtension = Path.GetFileNameWithoutExtension(path);
As Pointed out by peter i forgot about the original directory so you can use Path.Combine
and Path.GetDirectoryName(path)
as shown in peters answer
using System.IO;
string linkWithoutExtension = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path));
精彩评论