[HttpPost]
Public ActionResult Upfile ()
{
int count = Request.Files.Count;
for (int i = 0; i < count; i++)
{
WebTest.Entity.FileInfo FileInfo = new WebTest.Entity.FileInfo ();
HttpPostedFileBase file = Request.files[i];
string[] Nametpye = file. Filename.split (new char[] {'. '});
String Path = "/image/upword/" + DateTime.Now.ToString ("yyyymmddhhmmssffff");
String FilePath = Server.MapPath (Path);
if (! Directory.Exists (FilePath))
{
Directory.CreateDirectory (FilePath);
}
File. SaveAs (FilePath + "/" + file. FileName);
Fileinfo.filename = nametpye[0];
Fileinfo.filetype = "." + nametpye[1];
Fileinfo.fileurl = Path + "/" + file. FileName;
Fileinfo.refnum = 1;
fileinfo.refnumtable = "News";
Fileinfo.size = (file. contentlength/1024). ToString ();
Db. Set<webtest.entity.fileinfo> (). ADD (FileInfo);
}
int res = db. SaveChanges ();
if (res > 0)
{
Return Content ("OK: Upload file successfully! ");
}
Else
{
Return Content ("NO: Upload file failed!") ");
}
}
Upload a picture background notation