如何在MVC核心2控制器中重命名图像。?
以下代码无效,无法完成任务:
string savelocation = path;
string fileExtention = System.IO.Path.GetExtension(files[0].FileName);
//creating filename to avoid file name conflicts.
string NewName = id.ToString();// id is actually the Primary key
//saving file in savedImage folder.
var savePath = savelocation + NewName + fileExtention;
string result2 = "/uploads/" + user + "/" + Path.GetFileName(savePath);
var stream3 = new FileStream(NewName, FileMode.Create);
files[0].CopyTo(stream3);
stream3.Flush();
stream3.Dispose();
答案 0 :(得分:0)
我发现了问题,我改变了我的代码,这是新的工作代码
var stream3 = new FileStream(NewName, FileMode.Create);
已更改为
var stream3 = new FileStream( savePath, FileMode.Create);