// ghi từ db vào file nhãn public ActionResult WriteFile(string key) { //format: a01-000u-00-00| ok| 154| 408 768 27 51| AT| A // get key try { //string keyEn = Commons.StringHelper.stringToSHA512(key); var dbKey = db.Khoas.FirstOrDefault().KeyValue; dbKey = string.IsNullOrEmpty(dbKey) == true ? "ẹc" : dbKey; if (key == dbKey) { List <string> listFileName = new List <string>(); List <string> listLable = new List <string>(); // lấy list nhãn đã gán var listCroped = db.ImageCropeds.ToList(); // lấy ra tên hình ảnh foreach (var crop in listCroped) { listFileName.Add(db.Images.Find(crop.ImageId).Uri); // dùng cho 1 hình string nameImage = db.Images.Find(crop.ImageId).Name; // dùng với hình đã cắt // string nameFile = crop.Image.Name + "-" + crop.Line + "-" + crop.Index; // nhãn listLable.Add(nameImage + " " + crop.Info); } string comment = "#NGuoiTao_NguyenAnhDung" + DateTime.Now.ToString() + "#"; string temp = "/TrainingFile/"; string word = "word.txt"; string pathFile = Path.Combine(temp, word); string path = Server.MapPath("~" + pathFile); if (!System.IO.File.Exists(path)) { FileHelper.CreateFile(path, comment); } foreach (var item in listLable) { FileHelper.AppenAllText(path, "\n" + item); } return(Json(new ExecuteResult() { Isok = true, Data = "path", Message = "Is ok" }, JsonRequestBehavior.AllowGet)); } return(Json(new ExecuteResult() { Isok = false, Data = null, Message = "Key k đúng hoặc k có quyền ghi file" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new ExecuteResult() { Isok = false, Data = null, Message = ex.Message }, JsonRequestBehavior.AllowGet)); } }