How to use CKSource.FileSystem.Local in an ASP.NET solution (not MVC)

I found this document for manual integration , but only MVC.

I tried integration logic for ASP.NET, but I can not do the same.

Does anyone know a document that shows how to do this?

I need to use CKSource.FileSystem.Local, but the main problem is that we cannot configure the CKfinder 3 connector to work with CKEditor 4.6 with ASP.NET WebForms.

thank

+4
source share
1 answer

, CKSource.FileSystem.Local. . , , . , , .

, . filebrowserBrowseUrl filebrowserImageBrowseUrl, .

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="ckeditor.js"></script>

<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Text="<p>This is a demo text.</p>"></asp:TextBox>

<script type="text/javascript">
    $(document).ready(function () {
        CKEDITOR.replace('<%=TextBox1.ClientID %>', {
            filebrowserBrowseUrl: '/CKFileBrowser.aspx?type=doc',
            filebrowserImageBrowseUrl: '/CKFileBrowser.aspx?type=img'
        });
    });
</script>

CKFileBrowser.aspx, , . GridView DataList , .

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="ckeditor.js"></script>

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" CssClass="filesHolder">
    <Columns>
        <asp:TemplateField HeaderText="Name">
            <ItemTemplate>
                <%# Eval("Name") %>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Size">
            <ItemTemplate>
                <%# string.Format("{0:N0}", Convert.ToInt32(Eval("Length")) / 1024) %> kb
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

<asp:DataList ID="DataList1" runat="server" RepeatColumns="4" CellPadding="10" CssClass="thumbnailHolder">
    <ItemTemplate>
        <img src="<%=defaultFolder %>/<%# Eval("Name") %>" />
    </ItemTemplate>
</asp:DataList>

<script type="text/javascript">
    var funcNum = '<%= Request.QueryString["CKEditorFuncNum"] %>';
    $(function () {
        $('#<%= GridView1.ClientID %> tr').click(function () {
            var fileUrl = '<%= baseUrl %>' + $(this).find("td:first").text().trim();
            window.opener.CKEDITOR.tools.callFunction(funcNum, fileUrl);
            window.close();
        });
    });
    $(function () {
        $('#<%= DataList1.ClientID %> img').click(function () {
            var fileUrl = $(this).attr('src').trim();
            window.opener.CKEDITOR.tools.callFunction(funcNum, fileUrl);
            window.close();
        })
    });
</script>

<style>
    .filesHolder tr {
        cursor: pointer;
    }

    .thumbnailHolder {
        float: left;
        margin: 0px 10px 10px 0px;
    }

        .thumbnailHolder img {
            max-width: 250px;
            max-height: 125px;
            cursor: pointer;
        }
</style>

Request.QueryString["CKEditorFuncNum"]. . JQuery click <tr> <img>, / .

, CKFileBrowser.aspx

public string defaultFolder;
public string baseUrl;

protected void Page_Load(object sender, EventArgs e)
{
    //set the default folder and the url for the files
    defaultFolder = "/files";
    baseUrl = Request.Url.Scheme + "://" + Request.Url.Authority + defaultFolder + "/";

    bool images_only = false;

    //check the type of popup
    if (Request.QueryString["type"] != null)
    {
        if (Request.QueryString["type"].ToString() == "img")
        {
            images_only = true;
        }
    }

    //build the popup items
    findTheFiles(images_only);
}

private void findTheFiles(bool images_only)
{
    //get all the files in the folder
    DirectoryInfo di = new DirectoryInfo(Server.MapPath(defaultFolder));
    FileInfo[] files = di.GetFiles().OrderBy(x => x.Name).ToArray();

    if (images_only == true)
    {
        //show only jpg or gif in the datalist
        DataList1.DataSource = files.Where(x => (x.Extension.ToLower() == ".jpg") || (x.Extension.ToLower() == ".gif")).ToList();
        DataList1.DataBind();
    }
    else
    {
        //display all files in the gridview
        GridView1.DataSource = files;
        GridView1.DataBind();
    }
}
+2

Source: https://habr.com/ru/post/1671750/


All Articles