logo 广告
Loading...
 导航 所在位置:论坛首页 -> ┈┋电脑网络┋┈ -> Asp/Asp.Net教程 -> ASP.Net程式中调用FCKeditor的接口
回复
标题:ASP.Net程式中调用FCKeditor的接口收藏 编辑 删除 楼主 | 上一篇 下一篇
晕菜两次
头像
等级:社区游民
权限:普通用户
积分:13
金钱:213
声望:16
经验:16
发帖数:47
注册:2008年4月20日
资料 短消息2008-4-26 11:41:47
在官方默认的版本中,FCKeditor是不支持asp.net的(没有供asp.net调用的接口),不过有一个供asp调用的接口,我根据fckeditor.asp这个文件用C#改写了一个.Net的接口,大家有需要可以参考。

  <script language="c#" runat="Server">
  public class FCKeditor
  {
   private string sBasePath;
   private string sInstanceName;
   private string sWidth;
   private string sHeight;
   private string sToolbarSet;
   private string sValue;

   private ArrayList oConfig;

  public FCKeditor()
  {
  sBasePath  = "/admin/FCKeditor/";
  sWidth   = "100%";
  sHeight   = "200";
  sToolbarSet  = "Default";
  sValue   = "";
  oConfig = new ArrayList();
  }

  public string BasePath
  {
  get{ return sBasePath; }
  set{ sBasePath = value; }
  }

  public string InstanceName
  {
  get{ return sInstanceName; }
  set{ sInstanceName = value; }
  }

  public string Width
  {
  get{ return sWidth; }
  set{ sWidth = value; }
  }

  public string Height
  {
  get{ return sHeight; }
  set{ sHeight = value; }
  }

  public string ToolbarSet
  {
  get{ return sToolbarSet; }
  set{ sToolbarSet = value; }
  }

  public string Value
  {
  get{ return sValue; }
  set{ sValue = value; }
  }

  public void Config(string configKey, string configValue)
  {
  oConfig.Add(new DictionaryEntry(configKey, configValue));
  }

  public void Create(string instanceName)
  {
  HttpContext.Current.Response.Write("<div>");
  if(IsCompatible())
  {
  string sFile="";
  string sLink="";
  if(HttpContext.Current.Request["fcksource"] == "true"){ sFile   ="fckeditor.original.html";}
  else{ sFile = "fckeditor.html"; }

  sLink = sBasePath + "editor/" + sFile + "?InstanceName=" + instanceName;

  if(sToolbarSet != "") sLink = sLink + "&Toolbar="+sToolbarSet;

  HttpContext.Current.Response.Write("<input type='hidden' id='" + instanceName + "'   name='" + instanceName + "' value='" + HttpContext.Current.Server.HtmlEncode( sValue ) + "' style='display:none' />");
  
  HttpContext.Current.Response.Write("<input type='hidden' id='"+instanceName+"___Config' value='"+GetConfigFieldString()+"' style='display:none' />");
  
  HttpContext.Current.Response.Write("<iframe id='"+instanceName+"___Frame' src='"+sLink+"' width='"+sWidth+"' height='"+sHeight+"' frameborder='no' scrolling='no'></iframe>");
   }
    else
    {
  string sWidthCSS="";
  string sHeightCSS="";
  
  if(sWidth.IndexOf('%')!=-1){ sWidthCSS = sWidth; }
  else{ sWidthCSS = sWidth+"px"; }

  if(sHeight.IndexOf('%')!=-1){ sHeightCSS = sHeight; }
  else{ sHeightCSS = sHeight+"px"; }

  HttpContext.Current.Response.Write("<textarea name='"+instanceName+"' rows='4' cols='40' style='width: "+sWidthCSS+"; height: "+sHeightCSS+"'>"+HttpContext.Current.Server.HtmlEncode(sValue)+"</textarea>");
  }
  HttpContext.Current.Response.Write("</div>");
  }

  private bool IsCompatible()
  {
  string sAgent = HttpContext.Current.Request.UserAgent;
  double iVersion;
  bool iIsCompatible = false;
  if( sAgent.IndexOf("MSIE") !=-1 &&
      sAgent.IndexOf("mac") ==-1 &&
  sAgent.IndexOf("Opera") == -1)
  {
  try{ iVersion = Convert.ToDouble(sAgent.Substring(sAgent.IndexOf("MSIE")+4,4).Trim()); }
  catch{ iVersion=0; }
  iIsCompatible = ( iVersion >= 5.5 );
  }
  else
  { iIsCompatible = false; }
  return iIsCompatible;
  }

  private string GetConfigFieldString()
  {
  string sParams="";
  bool bFirst = true;
  foreach(DictionaryEntry de in oConfig)
  {
  if(bFirst == false){ sParams = sParams+"&"; }
  else{ bFirst = false; }
  sParams = sParams+EncodeConfig( de.Key.ToString() )+ "=" +EncodeConfig  ( de.Value.ToString() );
  }
  return sParams;
  }
 
  private string EncodeConfig( string valueToEncode )
  {
  string sEncodeConfig;
  sEncodeConfig = valueToEncode.Replace("&", "%26" );
  sEncodeConfig = sEncodeConfig.Replace("=", "%3D" );
  sEncodeConfig = sEncodeConfig.Replace("'", "%22" );
  return sEncodeConfig;
  }
  }
  </script>

  使用方法:

  <%
 string sBasePath = Request.ServerVariables["PATH_INFO"];
  FCKeditor oFCKeditor = new FCKeditor();
  oFCKeditor.BasePath = "./FCKeditor/";
  oFCKeditor.Width = "100%";
  oFCKeditor.Height = "400";
  oFCKeditor.ToolbarSet = "Basic";
  oFCKeditor.Create("body");
  %>

  此外,这个编辑器的asp.net用的文件上传和浏览程序也是没有的,不过可以在配置文件里把asp设置为默认脚本语言就行了,一般支持asp.net的服务器都支持asp的,不过asp.net的程序就不可能直接调用asp的类了,因此我编写了这个接口。

签名

2008-4-26 11:41:47 顶部
第1页 共页 共0个回复     <<    >>    
 快速回复
  • 支持UBB,HTML标签

  • 高级回复

  • 操作选项:评分 加精 解精 奖惩 设专题 设公告 解公告 固顶 总固顶 解固顶 结帖 解结帖 锁帖 解锁 移帖 删帖
      首页 | 购买指南 | 虚拟主机 | 特色介绍 | 下载中心 | 支付方式
    Copyright 2004-2008 BBSGood.com Powered By: BBSGood.Speed Version 5.0
      咨询电话:0575-85513832、0575-85513825(传真)、7*24小时咨询服务:13606552007 不良信息举报中心 浙ICP备05029817号
      业务QQ:38958768、客服QQ1:415896239、客服QQ2:343896043、MSN:jccsxx@hotmail.com