sbLog.AppendFormat("密码:{0}<br/>", Request.Params["userPwd"]);
foreach (var item in Request.Params["hidFileNames"].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries))
{
sbLog.AppendFormat("文件新名称:{0};下载地址:<a href='{1}' target='_blank'>{0}</a><br/>", item, string.Format(path, item));
}
response.Status = 1;
}
catch (Exception ex)
{
sbLog.AppendFormat("异常信息:{0}", ex.Message);
}
finally
{
response.Data = sbLog.ToString();
}
return Json(response);
}
/// <summary>
/// 获取上传文件信息
/// </summary>
/// <returns></returns>
[HttpPost] public ContentResult D_A()
{
var response = new MoResponse();
response.Data = "上传失败";
try
{
Thread.Sleep(1000 * 3);
var fileCount = Request.Files.Count;
//保存文件地址
var uploadPath = @"D:DTTest";
var fileNames = string.Empty;
for (int i = 0; i < fileCount; i++)
{
var file = Request.Files[i];
if (file == null || string.IsNullOrEmpty(file.FileName)) { continue; }
var fileName = file.FileName;
var fileNewName = DateTime.Now.Ticks + fileName;
file.SaveAs(Path.Combine(uploadPath, fileNewName));
fileNames += fileNewName + "|";
}
if (!string.IsNullOrEmpty(fileNames))
{
response.Status = 1;
response.Data = fileNames.TrimEnd('|');
}
}
catch (Exception ex)
{
response.Data = ex.Message;
}
return Content(JsonConvert.SerializeObject(response));
}
好了插件需要讲解的就这么多,不知不觉有只剩我一个人了,该回家了,下面给出整体的代码,插件代码请使用连接获取:
插件下载地址:shenniu.upfile-0.0.1.js
Controller代码:
public class ErrorController : Controller
{
//
// GET: /Error/
public ActionResult Index()
{
return View();
}
[HttpPost] public ActionResult A()
{
var sbLog = new StringBuilder(string.Empty);
var fileCount = Request.Files.Count;
//访问上传文件地址
var path = @"http://localhost:1010/{0}";
//保存文件地址
var uploadPath = @"D:DTTest";
sbLog.AppendFormat("上传文件目录:{0}<br/>", uploadPath);
sbLog.AppendFormat("上传文件量:{0}<br/>", fileCount);
for (int i = 0; i < fileCount; i++)
{
var file = Request.Files[i];
if (file == null || string.IsNullOrEmpty(file.FileName)) { continue; }
var fileName = file.FileName;
var fileNewName = DateTime.Now.Ticks + fileName;
sbLog.AppendFormat("第:{0}个文件名称:{1}新名称:{2}下载地址:<a href='{3}' target='_blank'>{2}</a><br/>", i + 1, fileName, fileNewName, string.Format(path, fileNewName));










