Exemple #1
0
        public ActionResult UploadOrdenServicio(HttpPostedFileBase file, string ArchivoOrden, long pLiqId, long IncidenteId)
        {
            MemoryStream ms = new MemoryStream();

            file.InputStream.CopyTo(ms);
            file.InputStream.Position = ms.Position = 0;

            byte[] fileData = null;

            using (var binaryReader = new BinaryReader(ms))
                fileData = binaryReader.ReadBytes(Request.Files[0].ContentLength);

            if (!(Helper.GetImageFormat(fileData) == Helper.ImageFormat.jpeg))
            {
                return(Json(false, JsonRequestBehavior.AllowGet));
            }


            Session["ArchivoOrden"] = "";
            Session["Error"]        = "";
            if (string.IsNullOrEmpty(ArchivoOrden)) //si esta vacio es un alta (Subir archivo y llamar al método)
            {
                long pUsr = Convert.ToInt32(Session["usr_id"]);
                WSTercerosLiquidaciones.TercerosLiquidacionesSoapClient wsClient = new WSTercerosLiquidaciones.TercerosLiquidacionesSoapClient();
                wsClient.Open();
                DataSet ds = wsClient.SetOrdenServicio(pLiqId, IncidenteId, pUsr, 1);
                wsClient.Close();
                if (ds.Tables[0].Rows[0]["Resultado"].ToString() == "0")
                {
                    Session["Error"] = ds.Tables[0].Rows[0]["AlertaError"].ToString();
                    return(Json(ds.Tables[0].Rows[0]["AlertaError"].ToString(), JsonRequestBehavior.AllowGet));
                }
                ArchivoOrden = ds.Tables[0].Rows[0]["Archivo"].ToString();
            }
            //Subir el archivo
            string path = "~/liquidacionesImagenes/";

            if (!Directory.Exists(Server.MapPath(path) + ArchivoOrden.Substring(0, ArchivoOrden.LastIndexOf('\\'))))
            {
                Directory.CreateDirectory(Server.MapPath(path) + ArchivoOrden.Substring(0, ArchivoOrden.LastIndexOf('\\')));
            }
            string fileName = ArchivoOrden.Substring(ArchivoOrden.LastIndexOf('\\') + 1);

            file.SaveAs(Path.Combine(Server.MapPath(path) + ArchivoOrden.Substring(0, ArchivoOrden.LastIndexOf('\\')), fileName));
            Session["ArchivoOrden"] = ArchivoOrden;
            return(Json(ArchivoOrden, JsonRequestBehavior.AllowGet));
        }