Dživo Jelić
Dživo Jelić

Reputation: 2115

How to work with files in aspnetcore?

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

Answers (3)

enet
enet

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

error_handler
error_handler

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

AdrienTorris
AdrienTorris

Reputation: 9391

Same as before to check if file exists :

File.Exists(filepath)

Upvotes: 1

Related Questions