Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

155
Vistas
Upload file failed to save in Database

public JsonResult SaveAttachment(string buyerCode) { Dictionary<int, CheckSessionData> IDictionary = CheckSessionData.GetSessionValues(); long companyId = (long)IDictionary[1].Id; long userId = (long)IDictionary[3].Id;

        var buyer = DB.Buyers.FirstOrDefault(x => x.Code == buyerCode);
        string basePath = "~/Upload/BuyerAttachment/";
        string path = Server.MapPath(basePath);
        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }
        HttpFileCollectionBase files = Request.Files;
        List<string> filePathList = new List<string>();
        for (int i = 0; i > files.Count; i++)
        {
            HttpPostedFileBase file = files[i];
            var date = DateTime.Now.ToString().Replace('/', '_');
            string FilePath = Path.Combine(path, date.Replace(':', ' ') + file.FileName);
            file.SaveAs(FilePath);
            filePathList.Add(FilePath);
        }
        foreach (var item in filePathList)
        {
            var buyerAttachment = new Buyer_Attachment();
            buyerAttachment.BuyerId = buyer.BuyerId;
            buyerAttachment.DateOfEntry = DateTime.Now;
            buyerAttachment.EntryBy = userId;
            buyerAttachment.AttachmentURL = path;
            DB.Buyer_Attachment.Add(buyerAttachment);
        }

        try
        {
            DB.SaveChanges();
        }
        catch (Exception)
        {
            return Json(false, JsonRequestBehavior.AllowGet);
        }
        return Json(true);
    }
}

function SaveAttachment(code) { var files = $("#CustomerAttachment").get(0).files;

        var fileData = new FormData();

        for (var i = 0; i < files.length; i++) {
            fileData.append("fileInput", files[i]);
        }

        $.ajax({
            type: "POST",
            url: "/BuyerSimple/SaveAttachment?buyerCode="+code,
            dataType: "json",
            contentType: false, // Not to set any content header
            processData: false, // Not to process data
            data: fileData,
            success: function (result, status, xhr) {
                filePathList = result;
                $('#AttachmentPathList').val(result);
            },
            error: function (xhr, status, error) {
                alert(status);
            }
        });
    }
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda