I am building a windows explorer app for the web using ASP.NET/C# 3.5. I have a dynamic string that holds my path information. This string changes as you navigate the application. What I am trying to do is get the last “directory name” in my string so for example:
C:\Code\AppSettings
I would need to return AppSettings
If the string was:
C:\Code\AppSettings\Backup
Then I would need to return Backup
I am not savvy enough with string manipulation to get this correctly from a dynamic string. Any help or examples would be great.
Thanks!
Since you’re dealing with file/directory paths, it’s best to use the helper methods of the Path Class instead of string manipulation.
You can use the Path.GetFileName Method: