public static string GetFileNameWithoutExtension(string fileName, string extension) { if (string.IsNullOrEmpty(extension)) return fileName; return fileName.Substring(0, fileName.Length - extension.Length); } }