Im using scott hanselmans file upload code:
public ActionResult UploadFiles()
{ var r = new List();
foreach (string file in Request.Files)
{
HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase;
if (hpf.ContentLength == 0)
continue;
string savedFileName = Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
Path.GetFileName(hpf.FileName));
hpf.SaveAs(savedFileName);
r.Add(new ViewDataUploadFilesResult()
{ Name = savedFileName,
Length = hpf.ContentLength });
}
return View("UploadedFiles",r);
开发者_如何学编程
}
I dont want this to exist in the controller. rather call it as a static method in a utils.cs class
is this possible?
Yes, but you'll need to pass your request object in to the function, as an outside library won't have access to it.
public void UploadFile(HttpRequestBase request) { ... }
精彩评论