find the name of a json file in csharp

To find the name of a JSON file in C#, you can use the Directory.GetFiles() method provided by the System.IO namespace. The method takes two arguments, the path of the directory you want to search, and the file extension you want to filter the results by (in this case, .json).

main.cs
using System.IO;

string path = @"C:\path\to\directory";
string[] jsonFiles = Directory.GetFiles(path, "*.json");

foreach (string file in jsonFiles)
{
    Console.WriteLine(Path.GetFileName(file));
}
201 chars
10 lines

This will print out the name of each JSON file in the directory specified by the path variable. If you want to include the full path to the file, you can use the file variable directly instead of Path.GetFileName(file).

related categories

gistlibby LogSnag