here is the code
here's the code for the last posting!! :) if you correct it please let me know!! thanks in advance!!!
using System;
using System.Web;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.ComponentModel;
namespace Cohete.HttpInputFileReloaded
{
[DefaultProperty("Text"),ToolboxData("<{0}:HttpInpu tFileReloaded runat=server></{0}:HttpInputFileReloaded>")]
public class HttpInputFileReloaded : System.Web.UI.WebControls.WebControl,INamingContai ner
{
public TextBox txtRuta = new TextBox();
public ImageButton imgBtn = new ImageButton();
public HtmlInputFile inpFile = new HtmlInputFile();
[Category("Appearance"), Description("Clase para el TextBox")]
public string TextBoxClass
{
get
{
EnsureChildControls();
return txtRuta.CssClass;
}
set
{
EnsureChildControls();
txtRuta.CssClass = value;
}
}
[Category("Data"), Description("Archivo a transferir al servidor")]
public HttpPostedFile PostedFile
{
get
{
if (inpFile.PostedFile.InputStream.Length != 0)
{
return inpFile.PostedFile;
}
else
{
return null;
}
}
}
[EditorAttribute(typeof(System.Web.UI.Design.UrlEdi tor), typeof(System.Drawing.Design.UITypeEditor)),
Category("Appearance"), Description("Ruta en la que se encuentra la imagen del boton")]
public string RutaImagen
{
get
{
EnsureChildControls();
return imgBtn.ImageUrl;
}
set
{
EnsureChildControls();
imgBtn.ImageUrl = value;
}
}
protected override void CreateChildControls()
{
txtRuta.ID = "txtRuta";
txtRuta.ReadOnly = true;
txtRuta.Enabled = false;
Controls.Add(txtRuta);
inpFile.ID = "inpFile";
inpFile.Attributes.Add("style","display:none");
inpFile.EnableViewState = true;
Controls.Add(inpFile);
imgBtn.ID = "imgBtn";
Controls.Add(imgBtn);
}
protected override void OnPreRender(EventArgs e)
{
if(!this.Page.IsClientScriptBlockRegistered("HtmlI nputFileCode"))
{
string strScript = "<script language=\"JavaScript\" type=\"text/javascript\">" +
"function HandleFileButtonClick(InputName,TextName)" +
"{" +
" document.getElementById(InputName).click(); " +
" document.getElementById(TextName).value = document.getElementById(InputName).value; " +
"} " +
"</script>";
this.Page.RegisterClientScriptBlock("HtmlInputFile Code",strScript);
}
imgBtn.Attributes.Add("OnClick","javascript:Handle FileButtonClick('" + this.ID + "_" + this.inpFile.ID + "','" + this.ID + "_" + this.txtRuta.ID + "');");
}
protected override object SaveViewState()
{
EnsureChildControls();
object[] state = new object[2];
object objBase = base.SaveViewState();
state[0] = objBase;
state[1] = txtRuta.Text; ;
return state;
}
protected override void LoadViewState(object savedState)
{
object[] state = (object[])savedState;
base.LoadViewState (state[0]);
EnsureChildControls();
txtRuta.Text = state[1].ToString();
}
public void SaveAs(string FileWithPath)
{
if (inpFile.PostedFile.InputStream.Length != 0)
{
inpFile.PostedFile.SaveAs(FileWithPath);
}
}
}
}
|