Answer the question
In order to leave comments, you need to log in
How to get a list of files via WebApi in C#?
Goodnight. Can you please tell me how can I get a list of files via webapi?
I have a method in the controller that should just return me a list of files in a specific folder, but the path to the files should be like
localhost:5000/api/files/file1.txt
localhost:5000/api/files/file2.txt
and so on so that the client can download them.
I use NetCore 3.1, there used to be a Server.MapPath method, now it has been removed.
Answer the question
In order to leave comments, you need to log in
List of files in a directory - https://docs.microsoft.com/en-us/dotnet/api/system...
send a file
[HttpGet("{id}")]
public async Task<FileStreamResult> Download(int id)
{
var filename = "file"+id.ToString()+".txt";
var path = "Путь к файлу";
var stream = File.OpenRead(path);
return new FileStreamResult(stream, "application/octet-stream")
{
FileDownloadName = fileName
};
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question