新客网WWW.XKER.COM:致力做中国最专业的网络学院!
学院: 操作系统 - 网络应用 - 服务器 - 网络安全 - 工具软件 - 办公软件 - Web开发 - 数据库 - 网页设计 - 图形图像 - 媒体动画 - 硬件学堂 - 存储频道 - QQ专区
您的位置:首页 > 软件开发 > .Net开发 > Asp.net教程 > 正文:ASP.Net程式中调用FCKeditor接口

ASP.Net程式中调用FCKeditor接口

新客网 XKER.COM 2008-04-27 来源:enet 收藏本文

在官方默认的版本中,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
 
{
  
getreturn sBasePath; }
  
set{ sBasePath = value; }
 }


 
public string InstanceName
 
{
  
getreturn sInstanceName; }
  
set{ sInstanceName = value; }
 }


 
public string Width
 
{
  
getreturn sWidth; }
  
set{ sWidth = value; }
 }


 
public string Height
 
{
  
getreturn sHeight; }
  
set{ sHeight = value; }
 }


 
public string ToolbarSet
 
{
  
getreturn sToolbarSet; }
  
set{ sToolbarSet = value; }
 }


 
public string Value
 
{
   
getreturn 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(
"

使用方法:

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

 

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

");
  
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(
"");
    }

    
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(
"  {
  
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>
标签:ASP.NET   FCKeditor  
收藏】 【评论】 【推荐】 【投稿】 【打印】 【关闭
发表评论
要记得去论坛讨论,点击注册新会员匿名评论
评论内容:不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
推荐阅读
阅读排行
随机推荐
实用信息推荐