Exemplo n.º 1
0
        public void InsertFoto(Foto foto, int webId)
        {
            try
            {
                string url = "http://www.moranvilla.com.ar/web/insertFormFoto";
                using (WebClient client = new WebClient())
                {
                    string id = Guid.NewGuid().ToString();
                    //Imagen original
                    var values = new NameValueCollection();
                    values["foto"]     = Convert.ToBase64String(foto.Imagen, Base64FormattingOptions.None);
                    values["filename"] = id + ".jpg";
                    values["inmueble"] = webId.ToString();
                    values["nuevo"]    = "si";

                    var result = client.UploadValues(url, values);

                    string hola = Encoding.UTF8.GetString(result);

                    values = new NameValueCollection();

                    //Imagen f75
                    Image  image75 = ResizeImage(foto.Imagen, 44, 75, true);
                    byte[] img75;
                    using (var ms = new MemoryStream())
                    {
                        image75.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                        img75 = ms.ToArray();
                    }
                    values["foto"]     = Convert.ToBase64String(img75, Base64FormattingOptions.None);
                    values["filename"] = id + "_h75.jpg";
                    values["inmueble"] = webId.ToString();
                    values["nuevo"]    = "no";

                    result = client.UploadValues(url, values);

                    hola = Encoding.UTF8.GetString(result);

                    //Imagen w280
                    Image  image280 = ResizeImage(foto.Imagen, 257, 430, false);
                    byte[] img280;
                    using (var ms = new MemoryStream())
                    {
                        image280.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                        img280 = ms.ToArray();
                    }
                    values["foto"]     = Convert.ToBase64String(img280, Base64FormattingOptions.None);
                    values["filename"] = id + "_w280.jpg";
                    values["inmueble"] = webId.ToString();
                    values["nuevo"]    = "no";

                    result = client.UploadValues(url, values);

                    hola = Encoding.UTF8.GetString(result);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }