private List <NoticiaFoto_ListarResult> NoticiaFoto_Obtener()
        {
            List <NoticiaFoto_ListarResult> lstNoticiaFoto = new List <NoticiaFoto_ListarResult>();

            try
            {
                foreach (UploadedFile file in rauArchivo.UploadedFiles)
                {
                    NoticiaFoto_ListarResult picture = new NoticiaFoto_ListarResult();
                    picture.urlImagen     = file.FileName;
                    picture.idNoticiaFoto = 0;
                    picture.descripcion   = "";
                    picture.activo        = true;
                    System.Drawing.Image img = System.Drawing.Image.FromStream(file.InputStream);
                    if (img.Width < img.Height)
                    {
                        picture.horizontal = false;
                    }
                    else
                    {
                        picture.horizontal = true;
                    }
                    lstNoticiaFoto.Add(picture);
                }
                return(lstNoticiaFoto);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        protected void btnGuardar_Click(object sender, EventArgs e)
        {
            if (Session["Usuario"] == null)
            {
                ScriptManager.RegisterStartupScript(Page, this.GetType(), "mykey", "CancelEdit();", true);
            }

            NoticiasWCFClient objNoticiasWCF = new NoticiasWCFClient();
            int idNoticia = 0;
            List <NoticiaFoto_ListarResult> lstFotos = JsonHelper.JsonDeserialize <List <NoticiaFoto_ListarResult> >((string)ViewState["lstFotos"]);

            try
            {
                if (string.IsNullOrEmpty(txtTexto.Text))
                {
                    throw new ArgumentException("Se debe ingresar un texto valido.");
                }

                if (string.IsNullOrEmpty(txtTitulo.Text))
                {
                    throw new ArgumentException("Se debe ingresar un título para la noticia");
                }

                if (DateTime.Compare(dpFechaPublicacion.SelectedDate.Value, dpFechaVencimiento.SelectedDate.Value) > 0)
                {
                    throw new ArgumentException("La fecha de publicación no puede ser despues de la fecha de vencimiento.");
                }

                if (Request.QueryString["idNoticia"] != "")
                {
                    idNoticia = int.Parse(Request.QueryString["idNoticia"]);
                    foreach (GridDataItem row in grdImagenes.Items)
                    {
                        NoticiaFoto_ListarResult foto = lstFotos.Find(x => x.idNoticiaFoto.ToString() == row["idNoticiaFoto"].Text);
                        foto.activo = ((RadButton)row.FindControl("btnSeleccionar")).Checked;
                        lstFotos.RemoveAll(x => x.idNoticiaFoto.ToString() == row["idNoticiaFoto"].Text);
                        lstFotos.Add(foto);
                    }
                }

                if (lstFotos.FindAll(x => !x.elimino).Count <= 0)
                {
                    throw new ArgumentException("Se debe guardar por lo menos un archivo valido.");
                }

                objNoticiasWCF.Noticia_Registrar(idNoticia, txtTitulo.Text, txtTexto.Text, dpFechaPublicacion.SelectedDate.Value, dpFechaVencimiento.SelectedDate.Value, int.Parse(cboEmpresa.SelectedValue), ((Usuario_LoginResult)Session["Usuario"]).idUsuario,
                                                 ckbActivo.Checked, lstFotos.ToArray());

                ScriptManager.RegisterStartupScript(Page, this.GetType(), "mykey", "CloseAndRebind(" + cboEmpresa.SelectedValue + ");", true);
            }
            catch (Exception ex)
            {
                lblMensaje.Text     = "ERROR: " + ex.Message;
                lblMensaje.CssClass = "mensajeError";
            }
        }
        protected void rauArchivo_FileUploaded(object sender, FileUploadedEventArgs e)
        {
            if (Session["Usuario"] == null)
            {
                ScriptManager.RegisterStartupScript(Page, this.GetType(), "mykey", "CancelEdit();", true);
            }

            try
            {
                String path = Server.MapPath("~/Images/Noticia");
                if (e.IsValid)
                {
                    string imgPath = Path.Combine(path, e.File.FileName);
                    e.File.InputStream.Dispose();
                    e.File.InputStream.Close();
                    e.File.SaveAs(imgPath, true);

                    //NoticiaFoto_ListarResult imagen = new NoticiaFoto_ListarResult();
                    NoticiaFoto_ListarResult picture = new NoticiaFoto_ListarResult();
                    picture.urlImagen     = e.File.FileName;
                    picture.idNoticiaFoto = 0;
                    picture.descripcion   = "";
                    picture.activo        = true;
                    picture.elimino       = false;
                    //System.Drawing.Image img = System.Drawing.Image.FromStream(e.File.InputStream);
                    System.Drawing.Image img = System.Drawing.Image.FromFile(imgPath);
                    if (img.Width < img.Height)
                    {
                        picture.horizontal = false;
                    }
                    else
                    {
                        picture.horizontal = true;
                    }
                    picture.altura  = img.Height;
                    picture.anchura = img.Width;
                    img.Dispose();

                    List <NoticiaFoto_ListarResult> lstFotos = JsonHelper.JsonDeserialize <List <NoticiaFoto_ListarResult> >((string)ViewState["lstFotos"]);
                    lstFotos.Add(picture);
                    ViewState["lstFotos"] = JsonHelper.JsonSerializer(lstFotos);
                }
            }
            catch (Exception ex)
            {
                lblMensaje.Text     = "Error: " + ex.Message;
                lblMensaje.CssClass = "mensajeError";
            }
        }