如何使用aspnetcore中的文件?

时间:2016-05-24 10:16:07

标签: c# asp.net asp.net-core-1.0

如何使用dotnetcore中的文件。

例如我们之前有过:

IFormFile file // you would get this by uploading a file
file.SaveAs(filePath);

如何检查文件是否存在。如何动态添加新文件... 无法找到有关在aspnetcore中处理文件的任何内容。

3 个答案:

答案 0 :(得分:1)

检查文件是否存在与以前相同:

File.Exists(filepath)

答案 1 :(得分:1)

您只需使用File类的Exists()方法检查文件。

bool exists = File.Exists(filePath);
if(!exists )
{
     file.SaveAs(filePath);
}

答案 2 :(得分:1)

转到https://docs.asp.net/projects/api/en/latest/autoapi/Microsoft/AspNet/FileProviders/index.html

您可以使用一系列类和接口来获得您想要的内容......