MS Word Editor

8 posts, 0 answers
  1. Orion
    Orion avatar
    15 posts
    Member since:
    Oct 2018

    Posted 31 Oct 2018 Link to this post

    We have ASP.NET web application which will be generating a word document based on various parameters and it will be saved in the server. In the next level of users want to edit the word document with in our application instead of downloading the file and make a changes on it. Does Telerik has any editor to support MS-Word documents?
  2. Rumen
    Admin
    Rumen avatar
    14437 posts

    Posted 01 Nov 2018 Link to this post

    Hello Orion,

    I have good news that RadEditor does offer import from and export to DOCX and RTF.

    You can find the documentation articles at

    as well as test the live demos on

    Best regards,

    Rumen
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.

  3. Orion
    Orion avatar
    15 posts
    Member since:
    Oct 2018

    Posted 01 Nov 2018 in reply to Rumen Link to this post

    Hi Rumen, I just want to achieve "Import Selected DOCX File" functionality which is implemented in live demo site through C# code. so that, word document will get open in RADEditor and user can make the changes with in editor. Then, I want to save it on the same server where it is hosted. Can you assist me on this?
  4. Rumen
    Admin
    Rumen avatar
    14437 posts

    Posted 01 Nov 2018 Link to this post

    Hi,

    You can import Word documents using the LoadDocxContent() method for DOCX content and LoadRtfContent() for RTF.

    These methods can be used with different overloads to best fit the application scenario:

    LoadDocxContent(Stream docxStream)—loads DOCX content from a Stream.
    LoadDocxContent(string docxText)—loads DOCX content from an ASCII-encoded String.
    LoadRtfContent(Stream rtfStream)—loads RTF content from a Stream.
    LoadRtfContent(string rtfText)—loads RTF content from an ASCII-encoded String.

    For more information check this article Importing from Word document.


    Regards,
    Rumen
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  5. Orion
    Orion avatar
    15 posts
    Member since:
    Oct 2018

    Posted 02 Nov 2018 in reply to Rumen Link to this post

    Thanks a lot Rumen. I'm able to import the content from Word Document to RADEditor using LoadDocxContent(Stream docxStream). Now, I'm trying to use ExportToDocx() method to export the content from the editor which I changed. But, I'm not gettig the content which I changed in the RADEditor in the exported document. Instead, the document has the same content when it was imported. Please let me know what should I need to be done to get the changed content after import
  6. Rumen
    Admin
    Rumen avatar
    14437 posts

    Posted 02 Nov 2018 Link to this post

    Hello,

    The problem could be due to that the editor content is overridden in the Page_Load method. Please note that if you read the content of the editor in an event handler (such as a button event handler) this event handler executes later in the page lifecycle compared to Page_Load. This is why, in case you set the initial content in Page_Load it is mandatory to add a check, e.g.

    if (!Page.IsPostBack)
    {
         RadEditor1.Content = "Some content";
         //or
         RadEditor1.LoadDocxContent(Stream docxStream);
    }

    You can also download a working demo of import from and export to Word from this code library Import and Export to DOCX by using the Telerik Document Processing library.

    ASPX:
    <telerik:RadEditor ID="RadEditor1" runat="server" ContentFilters="DefaultFilters, PdfExportFilter">
        <ExportSettings FileName="RadEditorExport" OpenInNewWindow="true"></ExportSettings>
    </telerik:RadEditor>
     
    <asp:Button Text="Export to DOCX" runat="server" ID="BtnExportToDOCX" OnClick="BtnExportToDocx_Click" />


    Codebehind:
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.IO;
     
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                SetInitialContent();
            }
        }
     
        private void SetInitialContent()
        {
            string filePath = Server.MapPath("~/SampleInitialContent.docx");
            byte[] fileBinaryData = File.ReadAllBytes(filePath);
            string convertedContent = DocxToHtmlConverter.ConvertDocxToHtml(fileBinaryData);
     
            RadEditor1.Content = convertedContent;
        }
     
        protected void BtnExportToDocx_Click(object sender, EventArgs e)
        {
            RadEditor1.Export(new RadEditorDocxExportEnhancement.TelerikDocxExportTemplate(RadEditor1));
        }
    }


    Download links:

    Best regards,
    Rumen
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  7. Orion
    Orion avatar
    15 posts
    Member since:
    Oct 2018

    Posted 02 Nov 2018 in reply to Rumen Link to this post

    Thanks Rumen! I have fixed the issue as per your input. Is there any option to import word document with "Paste from word"  feature in RADEditor programmatically? Because, the format has not been retained after exporting the word document from RADEditor. I manually copied the content via "Paste from word" option and tried to exprttoDocx which is retained the source document format. Can you please assist me to import word document with "Paste from word" feature?
  8. Rumen
    Admin
    Rumen avatar
    14437 posts

    Posted 02 Nov 2018 Link to this post

    Hi Orion,

    You can learn how the Paste option works in the following article Pasting Content Overview.

    the RadEditor’s paste functionality uses the browser’s DOM clipboard events.Therefore, any content pasted, is first processed by the browser. Images, HTML, MS Word, plain text etc., are data types that are first translated to HTML by the browser and then fetched via the clipboard event’s data to the editor. The content is already translated from Word syntax to HTML and RadEditor just consumes it. RadEditor does not have an idea what the content originally looked like and the pasting is controlled by the browser but not by RadEditor, which is similar to an enhanced <asp:TextBox> control.

    If you'd like to change something in the Pasted content prior the insertion in the editor, you can attach to the OnClientPasteHtml client event of RadEditor, check for the Paste command execution and modify the content provided by the args.get_value() method.

    <script type="text/javascript">
    function OnClientPasteHtml(sender, args)
    {
        var commandName = args.get_commandName();
        var value = args.get_value();
         
        if (commandName == "Paste")
        {
           // The StripPathsFilter() method receives as a parameter an array of strings (devided by a white space) that will be stripped from the absolute links.
            var domainName = "http://" + window.location.host; //returns the hostname and port number of the current URL
            var filter = new Telerik.Web.UI.Editor.StripPathsFilter([domainName]); //strip the domain name from the absolute path
                         
            var contentElement = document.createElement("SPAN");
            contentElement.innerHTML = value;
            var newElement = filter.getHtmlContent(contentElement);
            alert(newElement.outerHTML);
            args.set_value(newElement.outerHTML);  //set the modified pasted content in the editor
        }
    }
    </script>


    Regards,
    Rumen
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top