xheditor开源编辑器ajax上传功能的完善
編輯器很多大家肯定都不陌生,有名的fckeditor,ewebeditor...
這年頭倒霉的事都輪到我了,前不久我用aspx寫了個網站,也是幫學校寫的,關鍵是網絡辦老師郁悶,由于我用的是fckeditor,可是他非說這個東西有漏洞,于是我去網上找了些資料,哪個編輯器沒漏洞啊,我對老師無語啊,可能前不久我們學校網站被黑,老師慌了,他就是不讓我上傳...于是我就尋思著換個編輯器,那就搞個無名的,開源的,找來找去找到了xheditor,這個編輯器確實也可以,調用方便,不用改代碼很多,在aspx下就OK搞定,但這種開源的東西功能上肯定不過關啊,其中一個就是上傳,也就這個東西最關鍵。
官網上的最新版本就有一個php的開發版本(支持ajax上傳的),現在我要做的就是:對xheditor寫個在aspx下上傳的功能
xheditor的下載地址:http://code.google.com/p/xheditor/downloads/list
下面是編輯器的界面:
upload.aspx頁面代碼:
?
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
public partial class admin_Upload : System.Web.UI.Page
{
??? protected void Page_Load(object sender, EventArgs e)
??? {
??????? FileUpload.FileUpLoad fp = new FileUpload.FileUpLoad();
??????? fp.FilePath = "upload";
??????? Response.Write(fp.uploadFile(Request.Files["upload"]));
??? }
}
?
?
FileUpload.cs:
?
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;
/// <summary>
///FileUpload 的摘要說明
/// </summary>
public class FileUpload
{
??? public class FileUpLoad
??? {
??????? private string fileExtension;
??????? /// <summary>
??????? /// 上傳文件路徑
??????? /// </summary>
??????? public string FilePath
??????? {
??????????? get
??????????? {
??????????????? return filepath;
??????????? }
??????????? set
??????????? {
??????????????? filepath = value;
??????????? }
??????? }
??????? private string filepath;
??????? public string uploadFile(HttpPostedFile postedFile)
??????? {
??????????? string fileName = Path.GetFileName(postedFile.FileName);
??????????? string fileExtension = Path.GetExtension(postedFile.FileName);
??????????? string phyPath = HttpContext.Current.Request.MapPath(FilePath);
??????????? DirectoryInfo upDir = new DirectoryInfo(phyPath);
??????????? //判斷上傳路徑是否存在,不存在則創建
??????????? if (!upDir.Exists)
??????????? {
??????????????? upDir.Create();
??????????? }
??????????? //保存文件
??????????? try
??????????? {
??????????????? postedFile.SaveAs(phyPath + "\\" + fileName);
??????????????? return "{err:\"\",msg:\"../" + FilePath + "/" + fileName + "\"}";
??????????? }
??????????? catch (Exception e)
??????????? {
??????????????? throw new ApplicationException(e.Message);
??????????? }
??????? }
??? }
}
希望廣大的高手繼續更新完善...把這個接口做得更好!
?
轉載于:https://www.cnblogs.com/zhulidong/archive/2009/11/01/1593880.html
總結
以上是生活随笔為你收集整理的xheditor开源编辑器ajax上传功能的完善的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 091028 工作记录
- 下一篇: Jad一个好东西(转载)