//Subir archivos APRENDIZ Autor: 1000Via public IHttpActionResult UploadFileAprendiz() { try { var httpRequest = HttpContext.Current.Request; if (httpRequest.Files.Count > 0) { var fileSavePath = string.Empty; var docfiles = new List <string>(); var URLArchivo = ""; foreach (string file in httpRequest.Files) { var postedFile = httpRequest.Files[file]; var filePath = "C:/UploadedFiles/"; var GUID = Guid.NewGuid().ToString(); if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } fileSavePath = Path.Combine(filePath, GUID + "." + postedFile.FileName.Split('.')[1]); postedFile.SaveAs(fileSavePath); docfiles.Add(filePath); URLArchivo = "C:/UploadedFiles/" + GUID + "." + postedFile.FileName.Split('.')[1]; string e = Path.GetExtension(URLArchivo); if ((e != ".xlsx") && (e != ".xlsm") && (e != ".xls")) { return(Ok(new { success = false, message = "La extencion del archivo no es válida" })); } } string FilePath = URLArchivo.Split('/')[1]; Aprendices_TituladaDTO oAprendiz = new Aprendices_TituladaDTO(); //Aprendices_Tecnica oAprendiz = new Aprendices_Tecnica(); TecnicaBl otecnicaBL = new TecnicaBl(); var book = new ExcelQueryFactory(URLArchivo); var resultado = (from row in book.Worksheet("Hoja1") select row).ToList(); foreach (var values in resultado) { if (values[0] == "") { break; } else { if (values[3] != "Colegios") { var Aprendiz = otecnicaBL.AprendizCedula(values[0]); if (Aprendiz == null) { oAprendiz.Nombre = values[0]; oAprendiz.Apellido = values[1]; oAprendiz.TipoDocumento = values[2]; oAprendiz.Documento = values[3]; oAprendiz.Grado = values[4]; oAprendiz.Email = values[5]; oAprendiz.Telefono = values[6]; oAprendiz.Direccion = values[7]; oAprendiz.NombreAcudiente = values[8]; oAprendiz.TelAcudiente = values[9]; oAprendiz.NumeroFicha = values[10]; oAprendiz.Colegios = values[11]; oAprendiz.Estado = ""; otecnicaBL.GuardarAprendiz1(oAprendiz); } else { return(Ok(new { success = false, message = "No se encontró archivo" })); } } } } return(Ok(new { success = true, path = URLArchivo })); } else { return(Ok(new { success = false, message = "No File" })); } } catch (Exception exc) { return(Ok(new { success = false, message = exc.Message })); } }