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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值