由于公司的需要分用戶上傳功能,剛開始接觸CuteEditor覺得很頭痛,在網(wǎng)上這方面資料很少很少,都只說可以實(shí)現(xiàn)但確都沒有寫下代碼,后來自己看了看,發(fā)現(xiàn)在CuteEditor上傳是通過配置文件進(jìn)行的,我想如果給每個(gè)用戶都寫一個(gè)配置文件此問題不就解決了,然后就拿起家伙開始辦事,發(fā)現(xiàn)還真行,呵呵,以下是實(shí)現(xiàn)代碼!
CuteSoft_Client/CuteEditor/Configuration/Security是上文件的一些配置文件,其中包含了三個(gè)文件:Admin.config,Default.config,Guest.config配置文件里就是一些上傳大小呀,上傳路徑等
修改一下<security name="ImageGalleryPath">~/uploads</security>就知道,上傳就是根據(jù)這里來的
執(zhí)行流程就是 給用戶先創(chuàng)建一配置文件,然后在給他一上傳圖片的文件夾路徑,在把控件指向該用戶的配置文件就可以了,這樣就實(shí)現(xiàn)了分用戶上傳的功能
protected void Page_Load(object sender, EventArgs e)
...{
if (!IsPostBack)
...{
/ /這里選擇不同用戶登錄的用戶名
CreateDict("admin");
/**/////根據(jù)用戶讀取配置文件
Editor1.SecurityPolicyFile = "admin.config";
}
}
/**/////創(chuàng)建配置文件及上傳文件夾 private void CreateDict(string strName)
...{
if (!File.Exists(Server.MapPath("~/CuteSoft_Client/CuteEditor/Configuration/Security/" + strName + ".config")))
...{
//復(fù)制一個(gè)原有的配置文件
File.Copy(Server.MapPath("~/CuteSoft_Client/CuteEditor/Configuration/Security/admin.config"), Server.MapPath("~/CuteSoft_Client/CuteEditor/Configuration/Security/" + strName + ".config"));
//通過xml文檔對(duì)象讀取xml文件
XmlDocument xDoc = new XmlDocument();
xDoc.Load(Server.MapPath("~/CuteSoft_Client/CuteEditor/Configuration/Security/" + strName + ".config"));
//查找結(jié)點(diǎn)
XmlNodeList xmlList = xDoc.SelectSingleNode("configuration").SelectNodes("security");
//遍歷結(jié)點(diǎn)
foreach(XmlNode xNode in xmlList)
...{
//轉(zhuǎn)換成登錄者的地址s
switch (xNode.Attributes["name"].Value)
...{
case "ImageGalleryPath": xNode.InnerText = xNode.InnerText + "/" + strName; break;
case "MediaGalleryPath": xNode.InnerText = xNode.InnerText + "/" + strName; break;
case "FlashGalleryPath": xNode.InnerText = xNode.InnerText + "/" + strName; break;
case "FilesGalleryPath": xNode.InnerText = xNode.InnerText + "/" + strName; break;
}
}
//保存變化設(shè)置
xDoc.Save(Server.MapPath("~/CuteSoft_Client/CuteEditor/Configuration/Security/" + strName + ".config"));
//建立新目錄
if (!Directory.Exists(Server.MapPath("~/uploads/" + strName + "")))
Directory.CreateDirectory(Server.MapPath("~/uploads/" + strName + ""));
}
}
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)
點(diǎn)擊舉報(bào)。