public ApiResponse LoadFormList() { var returnFiles = new List <string>(); var formDir = Path.Combine(PublicFunc.GetDeployDirectory(), PublicFunc.GetConfigByKey_AppSettings("Form_Path")); if (!string.IsNullOrEmpty(formDir) && Directory.Exists(formDir)) { var files = Directory.GetFiles(formDir, "*.html", SearchOption.AllDirectories); files.ForEach(m => returnFiles.Add(PublicFunc.GetConfigByKey_AppSettings("TemplatePrefix") + Path.GetFileName(m))); } return(ApiOk(returnFiles)); }
public ApiResponse ImportUser() { string uploadPath = Path.Combine( PublicFunc.GetDeployDirectory(), PublicFunc.GetConfigByKey_AppSettings("Upload_Path")); HttpPostedFile file = HttpContext.Current.Request.Files[0]; string strPath = Path.Combine(uploadPath, file.FileName); if (!Directory.Exists(uploadPath)) { Directory.CreateDirectory(uploadPath); } file.SaveAs(strPath); var model = new TramUserImportListModel() { Lists = new List <TeamUserImportModel>(), User = new UserInfo() { //上传文件时,body为空,在ApiJsonMediaTypeFormatter中ReadFromStreamAsync时要出错 //在解决该问题之前,现在这里设置一下登录用户的UserID UserID = "0"//ActionContext.Request.Content.Headers.GetValues("UserID").FirstOrDefault() } }; var list = model.Lists; var ds = Utility.ExcelToDataSet(strPath, "select * from [Sheet1$]"); if (ds != null && ds.Tables[0] != null) { foreach (DataRow row in ds.Tables[0].Rows) { list.Add(new TeamUserImportModel { TeamName = row[0].ToString(), UserID = row[1].ToString(), UserName = row[2].ToString() }); } } if (list.Count > 0) { userService.ImportTeamUser(model); } if (File.Exists(strPath)) { File.Delete(strPath); } return(ApiOk(list)); }
public ApiResponse ImportTiKu() { string uploadPath = Path.Combine( PublicFunc.GetDeployDirectory(), PublicFunc.GetConfigByKey_AppSettings("Upload_Path")); HttpPostedFile file = HttpContext.Current.Request.Files[0]; //var file = new { FileName = "题库.xls" }; string strPath = Path.Combine(uploadPath, file.FileName); if (!Directory.Exists(uploadPath)) { Directory.CreateDirectory(uploadPath); } file.SaveAs(strPath); var baseModel = GetModelBase(); var ds = Utility.ExcelToDataSet(strPath, "select * from [Sheet0$]"); var model = new TiKuMasterModel(); model.User = baseModel.User; if (ds != null && ds.Tables[0] != null) { model.TiKuName = file.FileName.Substring(0, file.FileName.LastIndexOf('.')); model.InDate = DateTime.Now; model.InUser = baseModel.User.UserID; model.LastEditDate = DateTime.Now; model.LastEditUser = baseModel.User.UserID; model.Status = (int)TiKuStatus.WaitForActive; model.Details = new List <TiKuDetailModel>(); foreach (DataRow row in ds.Tables[0].Rows) { model.Details.Add(new TiKuDetailModel { TeamName = row["TeamName"].ToString(), ProcessName = row["ProcessName"].ToString(), NodeName = row["NodeName"].ToString() }); } } tiKuService.CreateTiKu(model); if (File.Exists(strPath)) { File.Delete(strPath); } return(ApiOk()); }
public ApiResponse UploadForm() { string uploadPath = Path.Combine( PublicFunc.GetDeployDirectory(), PublicFunc.GetConfigByKey_AppSettings("Form_Path")); HttpFileCollection files = HttpContext.Current.Request.Files; if (!Directory.Exists(uploadPath)) { Directory.CreateDirectory(uploadPath); } foreach (string fileName in files) { HttpPostedFile file = files[fileName]; if (file != null) { string strPath = Path.Combine(uploadPath, file.FileName); file.SaveAs(strPath); } } return(ApiOk()); }