});
6、上传文件后,控制器中的处理
/// <summary>
/// 上传项目报告
/// </summary>
/// <param name="id">项目id</param>
/// <param name="file"></param>
/// <returns></returns>
[httppost]
public actionresult uploadfile(int id, httppostedfilebase file)
{
if (file == null)
return content("没有选择文件");
if (authcontext.current == null)
return content("登录异常!");
using (var db = new entities())
{
var model = db.project.find(id);
if (model == null)
return content("项目异常!");
string path = string.format(@"control\{0}\{1}\{2}.hfrpt", datetime.now.year, datetime.now.month, datetime.now.tostring("dd-hhmmss"));
var key = filehelper.getfilename(path);
var temp = filehelper.getfilename(string.format(@"temp\{0}.hfrpt", datetime.now.tostring("yyyymmdd-hhmmss")));
file.saveas(temp);
var safekey = id.tostring() + "haifeng%";
encrypthelper.desencrypt(temp, key, safekey);
system.io.file.delete(temp);
model.reportfilepath = path;
var entry = db.entry(model);
entry.state = entitystate.modified;
db.savechanges();
return content("上传成功");
}
网友评论