public async Task <ActionResult> UploadExcelAsync() { try { IFormFile file = Request.Form.Files[HttpContext.Session.GetObjectFromJson <KorisnikModel>("LogovaniKorisnik").Uvoznik.AutoID.ToString()]; if (file.Length > 0) { int broj = 0; string Uvoznik = "00000" + HttpContext.Session.GetObjectFromJson <KorisnikModel>("LogovaniKorisnik").Uvoznik.AutoID.ToString(); Uvoznik = Uvoznik.Substring(Uvoznik.Length - 5, 5); var filePath = Path.Combine(VratiGlavnaFolder()); DirectoryInfo d = new DirectoryInfo(filePath); FileInfo[] files = d.GetFiles(Uvoznik + "_*").OrderByDescending(c => c.LastWriteTime).ToArray(); if (files.Length > 0) { broj = Convert.ToInt32(files[0].Name.Substring(6, 5)); } string strbr = "00000" + (broj + 1).ToString(); strbr = strbr.Substring(strbr.Length - 5, 5); filePath = Path.Combine(filePath, Uvoznik + "_" + strbr + "_" + "excel" + Path.GetExtension(file.FileName)); using (var fileStream = new FileStream(filePath, FileMode.Create)) { await file.CopyToAsync(fileStream); } LoggerDAO.CreateNewDocumentLog(Path.GetExtension(file.FileName), filePath, HttpContext.Session.GetObjectFromJson <KorisnikModel>("LogovaniKorisnik").Id); } } catch (Exception e) { e.StackTrace.ToString(); Response.StatusCode = 400; } return(new EmptyResult()); }
public async Task <ActionResult> UploadImporterAsync() { try { IFormFile file = Request.Form.Files["uvoznikFiles"]; if (file.Length > 0) { var filePath = Path.Combine(CreateUvoznikFolder(), Path.GetFileName(file.FileName)); using (var fileStream = new FileStream(filePath, FileMode.Create)) { await file.CopyToAsync(fileStream); } LoggerDAO.CreateNewDocumentLog(Path.GetFileName(file.FileName), filePath, HttpContext.Session.GetObjectFromJson <KorisnikModel>("LogovaniKorisnik").Id); } } catch (Exception e) { e.StackTrace.ToString(); Response.StatusCode = 400; } return(new EmptyResult()); }