<%@ Page Language="C#" AutoEventWireup="true"%>
<%@ Import Namespace="System.Xml" %>
CodeBehind="install.aspx.cs" Inherits="WebApplication1.fckeditor.install"
<script type="text/C#" runat="server">
public string basePath = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
basePath = Request.PhysicalApplicationPath.ToString();
}
public bool SettingConfig(string uploadfile)
{
bool state = false;
try
{
//创建文件夹
if (!System.IO.Directory.Exists(basePath + uploadfile))
System.IO.Directory.CreateDirectory(basePath + uploadfile);
string basePathConfig = basePath + "Web.config";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(basePathConfig); //加载你的XML文件
XmlNode appSettings = xmlDoc.SelectSingleNode("/configuration/appSettings");//查找bookstore
string[,] strs = new string[2, 2] { { "FCKeditor:BasePath", "/fckeditor/" }, { "FCKeditor:UserFilesPath", "/" + uploadfile + "/" } };
for (int i = 0; i < 2; i++)
{
XmlElement adds = xmlDoc.CreateElement("add");//创建book节点
adds.SetAttribute("key", strs[i, 0]);
adds.SetAttribute("value", strs[i, 1]);
appSettings.AppendChild(adds);
}
xmlDoc.Save(basePathConfig);
state = true;
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
return state;
}
public bool SetingJavaScript()
{
bool state = false;
string tempContent = string.Empty;
try
{
using (System.IO.StreamReader sr = new System.IO.StreamReader(basePath + "fckeditor\\fckconfig.js", System.Text.Encoding.UTF8))
{
tempContent = sr.ReadToEnd();
sr.Close();
}
tempContent = tempContent.Replace("FCKConfig.DefaultLanguage = 'en' ;", "FCKConfig.DefaultLanguage = 'zh-cn' ;").Replace("var _FileBrowserLanguage = 'asp' ;", "var _FileBrowserLanguage = 'aspx' ;").Replace("var _QuickUploadLanguage = 'asp' ;", "var _QuickUploadLanguage = 'aspx' ;");
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(basePath + "fckeditor\\fckconfig.js", false, System.Text.Encoding.UTF8))
{
sw.Write(tempContent);
sw.Flush();
}
state = true;
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
return state;
}
public bool CopyFile()
{
try
{
if (System.IO.File.Exists(basePath + "bin\\FredCK.FCKeditorV2.dll"))
System.IO.File.Delete(this.basePath + "fckeditor\\bin\\FredCK.FCKeditorV2.dll");
else
System.IO.File.Copy(this.basePath + "fckeditor\\bin\\FredCK.FCKeditorV2.dll", basePath + "bin\\FredCK.FCKeditorV2.dll");
}
catch (Exception ex)
{
Response.Write(ex.Message);
return false;
}
return true;
}
protected void BtSave_Click(object sender, EventArgs e)
{
SettingConfig(this.TbUploadPath.Text);
SetingJavaScript();
CopyFile();
Response.Write("success");
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
上传文件夹路径: <asp:TextBox ID="TbUploadPath" runat="server"></asp:TextBox>
<br />
<asp:Button ID="BtSave" runat="server" Text="保存" style="border:1px solid"
onclick="BtSave_Click" />
</div>
</form>
</body>
</html>
posted on 2010-04-08 09:45
sanmao 阅读(111)
评论(0) 编辑 收藏