MVC
/// <summary> /// 文件上传 /// </summary> /// <returns></returns> public JsonResult plupload(string name) { string msg = string.Empty; string strchunk = Request["chunk"]; string strchunks = Request["chunks"]; int chunk = 0; int chunks = 0; int.TryParse(strchunk, out chunk); int.TryParse(strchunks, out chunks); foreach (string upload in Request.Files) { if (upload != null && upload.Trim() != "") { string path = AppDomain.CurrentDomain.BaseDirectory + "Temp\\"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } System.Web.HttpPostedFileBase postedFile = Request.Files[upload]; string filename1 = Path.GetFileName(postedFile.FileName); string filename = name; string newFileName = filename; if (chunks>1) { newFileName = chunk + "_" + filename; } string fileNamePath = path + newFileName; postedFile.SaveAs(fileNamePath); if (chunks>1 && chunk + 1 == chunks) { using (FileStream fsw = new FileStream(path + filename, FileMode.Create, FileAccess.Write)) { BinaryWriter bw = new BinaryWriter(fsw); // 遍历文件合并 for (int i = 0; i < chunks; i++) { bw.Write(System.IO.File.ReadAllBytes(path + i.ToString() + "_" + filename)); bw.Flush(); } } } } } return Json(new { jsonrpc = "2.0", result = "", id = "id" }); }