在做一个Blog系统,用到FreeTextBox控件,在这里搜集一下网上的说明和使用:
对于FreeTextBox(版本3.1.6)在ASP.Net 2.0中使用,
放上下载地址:
下载最新版FreeTextBox(版本3.1.6),解压
FreeTextBox 3.1.6 (2006/07/18)
博客园本地下载: http://www.cnblogs.com/Files/cleo/FTBv3-1-6.zip
作者网站下载地址:http://freetextbox.com/download/
详细版本有哪些改进和修改历史可以看这里:http://freetextbox.com/download/changelog.aspx
只需要将:FreeTextBox.DLL ftb.imagegallery.aspx 和aspnet_client文件夹 拷入你的项目当中
打开ASP.Net2.0项目,添加引用。(如果添加过以前版本的FreeTextBox,先删除以前版本的引用)
将FreeTextBox添加到工具栏。(工具栏〉常规〉选择项〉浏览到DLL文件,添加)
Language = " zh-CN " runat = " server "
ButtonDownImage = " True "
toolbarlayout = " ParagraphMenu,
FontFacesMenu,
FontSizesMenu,FontForeColorsMenu,
FontForeColorPicker,FontBackColorsMenu,
FontBackColorPicker | Bold,Italic,
Underline,Strikethrough,Superscript,
Subscript,RemoveFormat | JustifyLeft,JustifyRight,
JustifyCenter,JustifyFull;BulletedList,
NumberedList,Indent,Outdent;CreateLink,Unlink,
InsertImage | Cut,Copy,Paste,Delete;
Undo,Redo,Print,Save | SymbolsMenu,StylesMenu,
InsertHtmlMenu | InsertRule,InsertDate,
InsertTime | InsertTable,EditTable;InsertTableRowAfter,
InsertTableRowBefore,DeleteTableRow;
InsertTableColumnAfter,
InsertTableColumnBefore,DeleteTableColumn | InsertForm,
InsertTextBox,InsertTextArea,
InsertRadioButton,
InsertCheckBox,InsertDropDownList,InsertButton | InsertDiv,
EditStyle,InsertImageFromGallery,Preview,SelectAll,
WordClean,NetSpell "
runat = " Server " > </ FTB:FreeTextBox >
上面代码中 将FreeTextBox中的功能按钮全部显示出来 并使语言为中文 设置上传图片的保存地址
在ftb.imageegallery.aspx 中 设置属性
<FTB:ImageGallery id="ImageGallery1"
SupportFolder="~/aspnet_client/FreeTextBox/"
AllowImageDelete="true" AllowImageUpload="true"
AllowDirectoryCreate="true" AllowDirectoryDelete="true" runat="Server"/>
是否允许删除图片 上传图片 是否允许创建文件夹 删除文件夹
在freetextbox 中 使用了 Imageegallery 上传图片 但是 在界面中是英文的
有汉化方法,就直接用FreeTextBox 3.14版改进与汉化就行了
3) FreeTextBox 属性设置
ImageGalleryPath = "~/image/upload" 上传默认路径
ImageGalleryUrl = "ftb.imagegallery.aspx?rif={0}&cif={0}" ftb.imagegallery.aspx的目录, 只能用相对目录,不可以用"~"
4) ImageGallery 的设置
ftb.imagegallery.aspx文件里
AllowDirectoryCreate - 能否建立文件夹
AllowDirectoryDelete - 能否删除文件夹
AllowImageUpload - 能否上传图片
AllowImageDelete - 能否删除图片
AcceptedFileTypes - 可以上传文件扩展名的数组(array)
JavaScriptLocation ="InternalResource" UtilityImagesLocation ="InternalResource"
SupportFolder ="~/aspnet_client/FreeTextBox/"
AllowImageDelete =true
AllowImageUpload =true
AllowDirectoryCreate =false
AllowDirectoryDelete =false
runat ="Server" />
为开发者提供的2个属性
CurrentDirectories - a string[] array of directories to allow the user to navigate toward
CurrentImages - a FileInfo[] array of files the user should be able to insert.
建议: 删掉Page_Load事件可以显著回避上传图片不能即时显示的问题. 不要重写Page_Load
5) 得到保存编辑的内容
2 {
3 // 指向同一个委托
4 this.FreeTextBox1.SaveClick += new System.EventHandler this .FreeTextBox1_SaveClick);
5 this.Button1.Click += new System.EventHandler(this .FreeTextBox1_SaveClick);
6 }
7
8 private void FreeTextBox1_SaveClick(object sender, System.EventArgs e)
9 {
10 divshow.InnerHtml = FreeTextBox1.Text;
11 }
6.在test.aspx 中,加图片的路径
<FTB:FreeTextBox id="FreeTextBox1" runat="server" Width="700" ButtonPath="images/ftb/office2000/"/>
this.FreeTextBox1.Text 这个就是FTB中你输入的文本的内容,这是带HTML标记的
this.FreeTextBox1.HtmlStrippedText 这个是将HTML标记去掉的文本
7.写入数据库
在CSDN上看到朋友们说怎么把FreeTextBox内容写入数据库中
我做了一下.就是把所有产生的HTML代码都插入数据库的一个字段中
可以做一个新闻表
news
字段ID(自增) content addtime(getdate)
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (!IsPostBack)
{
SqlConnection myConn = new SqlConnection("server=(local);database=mm;uid=sa;pwd=123");
SqlCommand myCmd = new SqlCommand("select * from test where id=2",myConn);
myConn.Open();
SqlDataReader myDr;
myDr=myCmd.ExecuteReader();
myDr.Read();
Response.Write(myDr["content"].ToString());
myDr.Close();
myConn.Close();
}
}
private void Button1_Click(object sender, System.EventArgs e)
{
SqlConnection myConn = new SqlConnection("server=(local);database=mm;uid=sa;pwd=123");
SqlCommand myCmd = new SqlCommand("insert into test (content) values('"+FreeTextBox1.Text+"')",myConn);
myConn.Open();
myCmd.ExecuteNonQuery();
myConn.Close();
}