I am using Directory.GetFile() method to give me the list of all .txt files in my application path. Unfortunately it returns something like “C:/Document and setting/etc…/lol.txt”, the whole directory path with the file name and I cant display that on the listbox on my page. So, I thought I would make a For Loop that goes through each character in the string starting from right until it reaches “/” sign, then it removes the rest of the patch leaving only the file name.
I googled all “C# format string methods” and “edit strings C#” and “string methods C#” and came up with nothing useful.
I don’t really need the loop that does that, I only need the functions that will help me make the loop. Also, if theres an alternative to Directory.GetFile() method that returns only the file names would be more appreciated.
Is theres some sort of a website which has Net library explained and sorted under categories…? I mean, it would have been impossible to discover GetFileName() method by myself if you didn’t introduce me to it, Moreover, to find methods in C# that formats/edits plain strings.
Yeah, you definitely can use the Path.GetFileName to get the name of the file, but if you want a string manipulation, then you can split your result with character “/” and then select the last part of the split. For example if the result you’re dealing with is added to a string variable pathFile, then you can do this