用freetextbox2.0,自定义一个按钮插入内容设为
<img src="xxx/xx.jpg" width="230" height="234">

解决方案 »

  1.   

    你可以读这个图片,然后在用写字节,然后在保存在page上,在page写入以iamage形式page type
      

  2.   

    楼主:
    一般将图片写入数据库中的目的是防止远程图片(非本地服务器图片)被移除,出现空白红叉,所以:
    图片可以使用XMLHTTP或WebClient+正则表达式下载到本地服务器(建议保存在某个特定的图片文件夹中),然后更改为本地服务器图片文档的链接即可。
      

  3.   

    不好意思。写错了:
    目的是不想在客户端保存图片文件,把freetextbox的全部内容(包括图片)全部写入数据库中。
    应该是不想在服务器端保存图片文件
      

  4.   

    peterhao(青哥) 的思路是对的。但不知怎样实现
    johnsuna(缘来是e) :写入数据库还有很多好处:安全可控;易于管理维护等。
      

  5.   

    不用改FREETEXTBOX的代码,直接在后面加一些代码,比如:using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.IO;
    using System.Data.SqlClient;namespace WindowsApplication21
    {
     /// <summary>
     /// Form1 的摘要说明。
     /// </summary>
     public class Form1 : System.Windows.Forms.Form
     {
      private System.Windows.Forms.Button button1;
      private System.ComponentModel.IContainer components;
      private string ConnectionString = "Integrated Security=SSPI;Initial Catalog=;Data Source=localhost;";
      private SqlConnection conn = null; 
      private System.Windows.Forms.Button button2;
      private System.Windows.Forms.PictureBox pic1;
      private System.Windows.Forms.OpenFileDialog openFileDialog1;
      private System.Windows.Forms.ImageList imageList1;
      private System.Windows.Forms.TextBox textBox1;
      private System.Windows.Forms.Label label2;
        public Form1()
      {
       //
       // Windows 窗体设计器支持所必需的
       //
       InitializeComponent();
       conn = new SqlConnection(ConnectionString);    //
       // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
       //
      }  /// <summary>
      /// 清理所有正在使用的资源。
      /// </summary>
      protected override void Dispose( bool disposing )
      {
       if (conn.State == ConnectionState.Open)
        conn.Close();
       if( disposing )
       {
        if (components != null) 
        {
         components.Dispose();
        }
       }
       base.Dispose( disposing );  }  #region Windows Form Designer generated code
      /// <summary>
      /// 设计器支持所需的方法 - 不要使用代码编辑器修改
      /// 此方法的内容。
      /// </summary>
      private void InitializeComponent()
      {
       this.components = new System.ComponentModel.Container();
       this.button1 = new System.Windows.Forms.Button();
       this.pic1 = new System.Windows.Forms.PictureBox();
       this.button2 = new System.Windows.Forms.Button();
       this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
       this.label2 = new System.Windows.Forms.Label();
       this.imageList1 = new System.Windows.Forms.ImageList(this.components);
       this.textBox1 = new System.Windows.Forms.TextBox();
       this.SuspendLayout();
       // 
       // button1
       // 
       this.button1.Location = new System.Drawing.Point(0, 40);
       this.button1.Name = "button1";
       this.button1.Size = new System.Drawing.Size(264, 48);
       this.button1.TabIndex = 0;
       this.button1.Text = "加入新的图片";
       this.button1.Click += new System.EventHandler(this.button1_Click);
       // 
       // pic1
       // 
       this.pic1.Location = new System.Drawing.Point(280, 8);
       this.pic1.Name = "pic1";
       this.pic1.Size = new System.Drawing.Size(344, 264);
       this.pic1.TabIndex = 3;
       this.pic1.TabStop = false;
       // 
       // button2
       // 
       this.button2.Location = new System.Drawing.Point(0, 104);
       this.button2.Name = "button2";
       this.button2.Size = new System.Drawing.Size(264, 40);
       this.button2.TabIndex = 4;
       this.button2.Text = "从数据库中恢复图像";
       this.button2.Click += new System.EventHandler(this.button2_Click);
       // 
       // openFileDialog1
       // 
       this.openFileDialog1.Filter = "\"图像文件(*.jpg,*.bmp,*.gif)|*.jpg|*.bmp|*.gif\"";
       // 
       // label2
       // 
       this.label2.Location = new System.Drawing.Point(0, 152);
       this.label2.Name = "label2";
       this.label2.Size = new System.Drawing.Size(264, 48);
       this.label2.TabIndex = 5;
       // 
       // imageList1
       // 
       this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
       this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
       this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
       // 
       // textBox1
       // 
       this.textBox1.Location = new System.Drawing.Point(96, 208);
       this.textBox1.Name = "textBox1";
       this.textBox1.Size = new System.Drawing.Size(64, 21);
       this.textBox1.TabIndex = 6;
       this.textBox1.Text = "";
       // 
       // Form1
       // 
       this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
       this.ClientSize = new System.Drawing.Size(632, 445);
       this.Controls.AddRange(new System.Windows.Forms.Control[] {
                        this.textBox1,
                        this.label2,
                        this.button2,
                        this.pic1,
                        this.button1});
       this.Name = "Form1";
       this.Text = "Form1";
       this.Load += new System.EventHandler(this.Form1_Load);
       this.ResumeLayout(false);  }
      #endregion  /// <summary>
      /// 应用程序的主入口点。
      /// </summary>
      [STAThread]
      static void Main() 
      {
       Application.Run(new Form1());
      }  private void button1_Click(object sender, System.EventArgs e)
      {  
       openFileDialog1.ShowDialog ();   if (openFileDialog1.FileName.Trim()!="")
       {
        FileInfo fi = new FileInfo(openFileDialog1.FileName);
        string imgtitle=openFileDialog1.FileName; 
        int imgdatalen=(int)fi.Length;   
        byte[] imgdata = new byte[imgdatalen];
        Stream imgdatastream=fi.OpenRead(); 
        int n=imgdatastream.Read(imgdata,0,imgdatalen);
        if( conn.State == ConnectionState.Open)
         conn.Close();  
        ConnectionString ="Integrated Security=SSPI;" + "Initial Catalog=mydb;" +"Data Source=localhost;";        
        conn.ConnectionString = ConnectionString;
        
        try
        {
         string mySelectQuery = "INSERT INTO ImageStore(imgdata) VALUES (@imgdata )";
       
         SqlCommand myCommand = new SqlCommand(mySelectQuery, conn);
         SqlParameter paramData = new SqlParameter( "@imgdata", SqlDbType.Image );
         paramData.Value = imgdata;
         myCommand.Parameters.Add( paramData );     conn.Open();  
         int numRowsAffected = myCommand.ExecuteNonQuery();
         conn.Close();     MessageBox.Show("成功放入图片到数据库中"); 
        }
        catch(Exception err)
        {
         MessageBox.Show("您输入名称可能在数据库中已存在或输入为空,请检查!"+err.ToString() );
        }
        finally
        {}    
       }  }    private void button2_Click(object sender, System.EventArgs e)
      {
       if( conn.State == ConnectionState.Open)
        conn.Close();
       ConnectionString ="Integrated Security=SSPI;" + "Initial Catalog=mydb;" +"Data Source=localhost;";        
       conn.ConnectionString = ConnectionString;
       string sql="SELECT *  FROM ImageStore where id="+textBox1.Text.Trim() ;
       SqlCommand command = new SqlCommand(sql, conn);
         try
       {
        conn.Open();
       }
       catch
       {
        MessageBox.Show(" 不能打开数据联接!") ;
       }
                   
       
       SqlDataReader dr = command.ExecuteReader();
       
       if(dr.Read())
       {
        
        byte[] mydata=((byte[])dr["imgdata"]);
        MemoryStream myStream=new MemoryStream();
        foreach(byte a in mydata)
        {
         myStream.WriteByte(a); 
        }
        Image myImage=Image.FromStream(myStream); 
        myStream.Close();
                   pic1.Image=myImage;
        pic1.Refresh();
        
       }
       else
       { 
        MessageBox.Show("没有成功读入数据!") ;
       
       }
            
      conn.Close();
       
            
      }    
     }
    }这样就写入数据库了!
      

  6.   

    <Form id="Form1" method="post" Runat="server" Enctype="multipart/form-data">
    <table cellSpacing="1" cellPadding="3" width="578" align="center" border="0" borderColorLight="purple" height="96">
    <TR>
    <INPUT id="freetextbox" type="file" runat="server"><FONT color="#ff0000"><FONT face="宋体"></FONT><BR>
    </FONT>
    <BR>
    <BR>
    <asp:button id="Button1" runat="server" text="上传图片到数据库" Height="20px"></asp:button></TR>
    </table>
    </Form>
    这样调用HTML控件。然后
    Stream imgdatastream = freetextbox.PostedFile.InputStream;
      

  7.   

    兄弟们,都不行啊。
    littlehb(网际浪子) 的方法是普通的将图片写入和从数据库中读出,跟freetextbox没搭上勾。
     waterxmas(wx) 是搞错意思了。
      

  8.   

    johnsuna(缘来是e)看过你的文章。
    怎么样,想想办法吧。