public ActionResult Get(string nameSpace, string name) { byte[] retBytes; try { retBytes = _dictService.Get(nameSpace, name); } catch (DictionaryKeyNotFoundException ex) { var toThrow = new HttpException((int)HttpStatusCode.NotFound, "No value associated with this key.", ex); Util.LogBeforeThrow(toThrow, _log_props); throw toThrow; } return(File(retBytes, HttpUtil.OctetStreamContentType)); }
public ActionResult Upload(HttpPostedFileBase Filedata, string id) { // 如果没有上传文件 if (Filedata == null || string.IsNullOrEmpty(Filedata.FileName) || Filedata.ContentLength == 0) { return(this.HttpNotFound()); } string suffix = Path.GetExtension(Filedata.FileName); if (suffix != ".xlsx" && suffix != ".xls") { return(this.Json(new { code = 500, message = "模板文件格式错误" })); } Random random = new Random(); string name = string.Format("{0}{1}{2}", DateTime.Now.ToString("yyyyMMddHHmmssfff"), random.Next(10000, 99999), suffix); string virtualPath = string.Format("~/UploadFile/excel/{0}", name); string path = this.Server.MapPath(virtualPath); Filedata.SaveAs(path); var model = _itemService.Get(Convert.ToInt32(id)); var entity = _dictService.Get("temp", Convert.ToString(model.TempMode)); ImportService import = new ImportService(); string message = null; IEnumerable <ItemMaterial> list = import.ImportTemplet(path, model, entity.DictValue, out message); if (list != null) { _itemMaterialService.Add(list); if (model.IsNotice) { model.IsNotice = false; model.IsUpdate = true; _itemService.Update(model); } return(this.Json(new { code = 200, message = "模板文件上传成功" })); } else { return(this.Json(new { code = 200, message = message })); } }