public static void CreateLangProfile(HttpContext ctx, Models.Owner owner) { var prof = owner.langProfiles[0]; var path = System.IO.Path.Combine(owner.Path, $"{prof.ProfileName}_{DateTime.Now.ToString("yyyyMMMddHHmmss")}"); var fpath = System.IO.Path.Combine(path, "_langprofile.json"); System.IO.Directory.CreateDirectory(path); string keyidx = ctx.Request.Form["keyidxs"]; var lst = Newtonsoft.Json.JsonConvert.DeserializeObject <List <int> >(keyidx); lst.ForEach(t => { string inputtype = ctx.Request.Form["inptdata" + t.ToString()]; string inputlabel = ctx.Request.Form["inptlabel" + t.ToString()]; if (inputtype == "filesrc") { Microsoft.AspNetCore.Http.IFormFile fll = ctx.Request.Form.Files["uplfile" + t.ToString()]; string llpath = System.IO.Path.Combine(path, "LangData", "upl_File_" + (inputlabel ?? "") + "_" + fll.FileName); if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(llpath))) { System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(llpath)); } using (var stream = new System.IO.FileStream(llpath, System.IO.FileMode.Create)) { fll.CopyTo(stream); } prof.Files.Add(new Models.LabelInput() { Label = inputlabel, FilePath = llpath }); } else if (inputtype == "textsrc") { string txt = ctx.Request.Form["upltext" + t.ToString()]; string llpath = System.IO.Path.Combine(path, "LangData", "upl_Text_" + (inputlabel ?? "") + "_" + Guid.NewGuid().ToString("n").Substring(0, 4) + ".txt"); if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(llpath))) { System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(llpath)); } System.IO.File.WriteAllText(llpath, txt); prof.Files.Add(new Models.LabelInput() { Label = inputlabel, FilePath = llpath }); } }); prof.Path = path; prof.ProfileFilePath = System.IO.Path.Combine(prof.Path, prof.ProfileName + ".bin.gz"); prof.CreatedAt = DateTime.UtcNow; prof.AccessedAt = DateTime.UtcNow; System.IO.File.WriteAllText(fpath, Newtonsoft.Json.JsonConvert.SerializeObject(prof)); }
public string Upload(Microsoft.AspNetCore.Http.IFormFile file, string path = "wwwroot/uploads") { var fileName = DateTime.Now.ToString("yyyyMMddHHmmssff") + Path.GetExtension(file.FileName); var uploadPath = Path.Combine(Directory.GetCurrentDirectory(), path, fileName); using (var stream = new FileStream(uploadPath, FileMode.Create)) { file.CopyTo(stream); } return(fileName); }
public IActionResult Create(urun urun, IFormFile photo) { urun.eklemetarihi = DateTime.Now; if (photo != null) { var path = Path.Combine(_environment.WebRootPath, "images", photo.FileName); var stream = new FileStream(path, FileMode.Create); photo.CopyTo(stream); resim pht = new resim() { resimAdi = photo.FileName, urunId = urun.urunId }; //urunRepo.saveImage(pht); urun.Resimyolu = photo.FileName; ViewBag.photo = photo.FileName; } urunRepo.Save(urun); return(RedirectToAction("Index", "urun")); }