Reputation: 2115
how to work with files in dotnetcore.
For example we had this before:
IFormFile file // you would get this by uploading a file
file.SaveAs(filePath);
How can i check if file exist. How can i dynamicaly add new files ... Couldnt find anything about working with files in aspnetcore.
Upvotes: 0
Views: 137
Reputation: 45626
Go to https://docs.asp.net/projects/api/en/latest/autoapi/Microsoft/AspNet/FileProviders/index.html
There is a list of classes and interfaces you may use to get what you want...
Upvotes: 1
Reputation: 1201
You can simply check the file using Exists() method of File class.
bool exists = File.Exists(filePath);
if(!exists )
{
file.SaveAs(filePath);
}
Upvotes: 1
Reputation: 9391
Same as before to check if file exists :
File.Exists(filepath)
Upvotes: 1