Asp.net为FCK添加图片删除功能

首先找到editor/filemanager/browser/default/frmresourceslist.html  这个文件,然后将这个文件里的

oListManager.GetFileRowHtml = function( fileName, fileUrl, fileSize )
{
 // Build the link to view the folder.
 var sLink = '<a href="#" οnclick="OpenFile(\'' + ProtectPath( fileUrl ) + '\');return false;">' ;

 // Get the file icon.
 var sIcon = oIcons.GetIcon( fileName ) ;

 return '<tr>' +
   '<td width="16">' +
    sLink +
    '<img alt="" src="images/icons/' + sIcon + '.gif" width="16" height="16" border="0"><\/a>' +
   '<\/td><td>&nbsp;' +
    sLink +
    fileName +
    '<\/a>' +
   '<\/td><td align="right" nowrap>&nbsp;' +
    fileSize +
    ' KB' +
  '<\/td><\/tr>' ;
}

 

替换成:

oListManager.GetFileRowHtml = function(fileName, fileUrl, fileSize) {
       // Build the link to view the folder.
       var sLink = '<a href="#" mce_href="#" οnclick="OpenFile(\'' + ProtectPath(fileUrl) + '\');return false;">';

       // Get the file icon.
       var sIcon = oIcons.GetIcon(fileName);

return '<tr>' + '<td width="16">' + sLink + '<img alt="" src="'+fileUrl+'" mce_src="'+fileUrl+'" width="32" height="32" border="0"> <\/a>' +
            '<\/td><td> ' + sLink + fileName + 
            '<\/a><td align="right" nowrap> ' + fileSize + ' KB' + '<a href="#" mce_href="#" οnclick="deleteFile(\'' + ProtectPath(fileUrl) + '\');" style="color: #FF9933;" mce_style="color: #FF9933;"> 删除 <\/a>' + '<\/td><\/tr>';

   }

然后找到editor/filemanager/browser/default/js/common.js 在最下面添加一个图片删除功能

//******************************** 图片删除功能 ******************************************

var req;                    //定义变量,用来创建xmlhttprequest对象
//产生不重复的随机数
var rn = Math.ceil(Math.random() * 1000000);
var rnch = rn;
function rndnum() {
    while (rn == rnch) rn = Math.ceil(Math.random() * 1000000);
    rnch = rn;
    return rn;
}
// 删除文件,Ajax开始
function deleteFile(file) {


    if (confirm("确定删除吗?")) {
        var url = "FCKdel_file.aspx?filePath=" + escape(file) + "&UD=" + rndnum();                  //要请求的服务端地址   
        if (window.XMLHttpRequest)                                                                  //非IE浏览器及IE7(7.0及以上版本),用xmlhttprequest对象创建   
        {
            req = new XMLHttpRequest();
        }
        else if (window.ActiveXObject)                                                              //IE(6.0及以下版本)浏览器用activexobject对象创建,如果用户浏览器禁用了ActiveX,可能会失败.   
        {
            req = new ActiveXObject("Microsoft.XMLHttp");
        }


        if (req)                                                                                    //成功创建xmlhttprequest
        {
            req.open("GET", url, true);                                                             //与服务端建立连接(请求方式post或get,地址,true表示异步)   
            req.onreadystatechange = callback;                                                      //指定回调函数   
            req.send(null);                                                                         //发送请求   
        }
    } else {
    return false;
    }


}
function callback() {
    Refresh();      //刷新一下 
}


最后在editor/filemanager/browser/default/下手动添加一个页面FCKdel_file.aspx

在FCKdel_file.aspx.cs里面添加如下代码:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string UD = Request.QueryString["UD"];      //生成的随机数
            string FilePath = Request.QueryString["filePath"];

            DeleteFile(FilePath);
        }
    }

    private void DeleteFile(string FileName)
    {
        string Result = "-2";

        if (string.IsNullOrEmpty(FileName))
        {
            Result = "0";                   // 文件删除失败!请检查文件是否存在!                
        }

        try
        {
            //string Root = System.AppDomain.CurrentDomain.BaseDirectory;     //当前应用程序目录
            //FileName = FileName.Replace("/SFS_BQW/", "");
            //System.IO.File.Delete(Root + FileName);
            System.IO.File.Delete(Server.MapPath(FileName));
        }
        catch
        {
            Result = "-2";                // 未知错误!                
        }

        Result = "1";
        Response.Write(Result);
    }

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值