이 항목을 편집 할 때 생성 될 때 이미지를 가져 오는 섹션이 있음 설명이나 이름을 변경하기 위해 이미지를 다시 업로드하지 않기를 바랍니다. .양식이 여러 번 업로드되었지만 수정 문제로 업로드 할 수 없음
내가 업로드 한 파일을 다루는 것을이 만든 : 하나의 이미지 (CurrentFileName) 필요한 경우
public void UploadFiles(string currentFileName, FormCollection form)
{ // loop through all files in form post
foreach (string file in Request.Files)
{
HttpPostedFileBase hpf = Request.Files[file];
// if no file is uploaded, we could be editing so set to current value
if (hpf.ContentLength == 0)
{
form[file] = currentFileName;
}
else
{ //rename the file unique so we dont clash with names
var filename = hpf.FileName.Replace(" ", "_").Replace(".", DateTime.Now.Date.Ticks + ".");
UploadFileName = filename;
hpf.SaveAs(Server.MapPath("~/Content/custom/" + filename));
// set the name of the file in our post to the new name
form[file] = UploadFileName;
}
}
// ensure value is still sent when no files are uploaded on edit
if(Request.Files.Count <= 0)
{
UploadFileName = currentFileName;
}
}
모두가 잘 작동하지만이 개 이미지의 총에 복용 사용할 수있는 새로운 이미지가 지금있다 그 때문에 currentFileName은 사용되지 않습니다. 아무도 이걸 다루지 못했고, 내가이 벽으로 벽을 때리는 방법. 문자열 [] currentFiles 생각하지만이 파일을 Request.Files의 문자열 파일과 비교하는 방법을 알지 못합니다.
만약 내가 모델을 넘겨 줄 수있을 정도로 모델을 다루는 데 도움이된다면 모델링을 할 수 있다고 생각합니다. 어떤 종류의 리플렉션없이 model.file을 할 수 있다고 생각합니다.
도움 주시면 감사하겠습니다.
감사
을 감상 할 수있다 = currentFiles [파일]; 이게 옳은 거니? 그렇다면 마지막 일에 대해 무엇을해야할까요? – davethecoder