Search code examples
c#.netclassreflectionstack-frame

Get Class Name with extension in C#?


I am trying to get class name with the extension (e.g. Employee.cs or Employee.aspx.cs) in my code. I was able to get the name of the class without the extension but does anybody know how can i also get extension of the class??

This is what i did to get class name:

var frame = new StackFrame(1);
string className = frame.GetMethod().ReflectedType.Name;

Solution

  • Call frame.GetFileName().
    This will only work if you have the PDB file.