KindEditor 上傳文件 在Asp.net中的使用


以前一直用FCK編輯器,因為配置比較簡單,但是發現Kindeditor這個編輯器更加好看,更加靈活,就用了下。

但是發現在上傳文件的時候,出現了大問題,弄了我好久的時間,為了記錄下,或許能幫助到您,共勉!

 

這里是官方網站,你可以去下載,查看相關文檔。

http://kindeditor.net/

 

我做了個簡單的界面,方便測試。

首先拷貝所有文件夾到工程目錄下;

 

拖了個簡單的界面,代碼如下,

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <script src="kindeditor-4.1.10/kindeditor.js" type="text/javascript"></script>
    <script src="kindeditor-4.1.10/lang/zh_CN.js" type="text/javascript"></script>
    <link href="kindeditor-4.1.10/plugins/code/prettify.css" rel="stylesheet" type="text/css" />
    <script src="kindeditor-4.1.10/plugins/code/prettify.js" type="text/javascript"></script>
    <script type="text/javascript">
        KindEditor.ready(function (K) {

            editor = K.create('textarea', {
                allowImageUpload: true,
                // uploadJson: 'kindeditor-4.1.10/asp.net/upload_json.ashx',
                fileManagerJson: 'kindeditor-4.1.10/asp.net/file_manager_json.ashx',

                //上傳文件后執行的回調函數,獲取上傳圖片的路徑
                afterUpload: function (url) {
                    alert(url);
                },
                //編輯器高度
                width: '700px',
                //編輯器寬度
                height: '450px;'
            });

        });

        function save() {
            editor.sync();
            var html = document.getElementById("txtContent").value;
            document.getElementById("<%=hdtxtContent.ClientID%>").value = html;
        }
    </script>
    <input id="hdtxtContent" type="hidden" runat="server" />
    <table width="100%" cellpadding="1" cellspacing="1" align="center">
        <tr>
            <td class="style1">
                文章分類:
            </td>
            <td>
                <asp:DropDownList ID="ddlSort" runat="server">
                    <asp:ListItem>國際新聞</asp:ListItem>
                    <asp:ListItem>國內新聞</asp:ListItem>
                    <asp:ListItem>四川新聞</asp:ListItem>
                </asp:DropDownList>
            </td>
        </tr>
        <tr>
            <td class="style1">
                文章標題:
            </td>
            <td>
                <asp:TextBox ID="txtTitle" runat="server" Width="500px"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="style1">
                文章內容:
            </td>
            <td>
                <%--  <asp:TextBox ID="content" name="content" TextMode="MultiLine" runat="server"></asp:TextBox>--%>
                <textarea id="txtContent" name="nmtxtContent" style="width: 700px; height: 200px;
                    visibility: hidden;"></textarea>
            </td>
        </tr>
        <tr>
            <td>
            </td>
            <td>
                <asp:Button ID="btnOK" runat="server" Text="提交" OnClick="btnOK_Click" OnClientClick="save();" />
            </td>
        </tr>
    </table>
</asp:Content>

 

界面就出來了

 

當我上傳圖片時,發現有問題。

 

當點擊確定時:

 

看起來很簡單的問題,花了我好久的時間,不過大多數應該是自己的配置問題。

解決方法就是添加下面2行代碼。

 

                uploadJson: 'kindeditor-4.1.10/asp.net/upload_json.ashx',
                fileManagerJson: 'kindeditor-4.1.10/asp.net/file_manager_json.ashx',

這兩句代碼非常關鍵,注意開始的時候我是注釋第一句代碼的,所以找不到路徑,默認是php的,我們這是Asp.net,不支持php,這里就報錯。

 

 我有個問題就是,當我們存儲長篇的內容到數據庫時,可能包括圖片,我們怎么存儲比較好,二進制?還是直接字符存儲?

 字符是比較占空間的,二進制轉換比較麻煩。

 

特別提示:當插入的時候會出現
 
“檢測到有潛在危險的 Request.Form 值.”這個錯誤提示
 
莫急:
 
vs2008解決方法,如下,任選一,
 
vs2010解決方法,需要下面兩個都寫入。
 
 
 
解決方案一: 
在.aspx文件頭中加入這句: 
<%@ Page validateRequest="false"  %> 
 
解決方案二: 
修改web.config文件: 
 
<configuration> 
  <system.web> 
    <httpRuntime requestValidationMode="3.5"/>
    <pages validateRequest="false" /> 
  </system.web> 
</configuration> 

 

因為validateRequest默認值為true。只要設為false即可。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM