This is a migrated thread and some comments may be shown as answers.

Can MS-Word document open via C# code in RADEditor?

12 Answers 203 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Orion
Top achievements
Rank 1
Orion asked on 01 Nov 2018, 08:17 AM
I just wanted to open document in RADEditor through C# code, instead of navigating File->Open link in RADEditor. If this is possible, I'll display the document link in my web application to open the respective document in RADEditor.So that, can edit the word document in RADEditor and save it on the server which is hosted. Let me know the case is possible.

12 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 01 Nov 2018, 08:34 AM
Hello Orion,

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.

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.
0
Orion
Top achievements
Rank 1
answered on 12 Nov 2018, 12:38 PM
Hi Rumen,  We want to know the list of MS-Word features which are currently offered by RADEditor. So that, we can come to know what are all the MS-Word features which are supported by RADEditor and which are doesn't. Like 1. Text Formatting - Yes;2. Inserting Image - Yes; 3. SpellCheck - Yes... Please share if you have any such documents...
0
Rumen
Telerik team
answered on 12 Nov 2018, 01:41 PM
Hello,

The MS Word like experience of RadEditor is demonstrated in the following demo: MS Word-like Experience.

The features like Bold, Italic, Underline, Strikethrough, Fore and Back Color, Insert Image, Insert Hyperlink and Insert Table are supported in the editor and in the exported DOCX file.
The Track Changes and Comments features are supported only inside RadEditor and will not persist in the exported DOCX file.

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.
0
Orion
Top achievements
Rank 1
answered on 14 Nov 2018, 08:33 AM
Hi Rumen, I enabled "SaveAs" option in Tool XML file and it brings "SaveAsDocX" option in the editor. When I click "SaveAsDocX" in the editor it's throwing "The command SaveDocx is not implemented yet in RADEditor" error. I that event has to be implemented in the code. Can you help me this? And, I've already implemented ExportDocx() and it's downloading the Docx file explicitly,  I just want to save the file where I originally imported (without explicit download).  To accommodate this save from where I imported, which option should I need to go among "ExportDocx()" or  "SaveAsDocx"?
0
Rumen
Telerik team
answered on 15 Nov 2018, 07:51 AM
Hi Orion,

The SaveAsDocX command executes the __doPostBack method to initiate a postback and on the server to call the ExportToDocx server method.

You can see how the SaveAsDocX command is implemented in the scripts.js file available with the demo installation as well as in the source code tab of the online demo:

scripts.js

Telerik.Web.UI.Editor.CommandList["SaveAsDocx"] =
Telerik.Web.UI.Editor.CommandList["SaveAsRtf"] =
Telerik.Web.UI.Editor.CommandList["SaveAsMarkdown"] =
Telerik.Web.UI.Editor.CommandList["SaveAsPDF"] = function (commandName, editor, args) {
    __doPostBack("", commandName);
};


DefaultCS.aspx.cs

protected void Page_Load(object sender, EventArgs e)
        {
            //select the Home tab by default
            RadEditor1.RibbonBar.SelectedTabIndex = 1;
            //handle postbacks from the export commands
            try
            {
                string evtArg = Request["__EVENTARGUMENT"];
                switch (evtArg)
                {
                    case "SaveAsDocx":
                        RadEditor1.ExportToDocx();
                        break;
                    case "SaveAsRtf":
                        RadEditor1.ExportToRtf();
                        break;
                    case "SaveAsPDF":
                        RadEditor1.ExportToPdf();
                        break;
                    case "SaveAsMarkdown":
                        RadEditor1.ExportToMarkdown();
                        break;
                    default:
                        break;
                }
            }
            catch (Exception ex)
            {
                RadNotification1.Show("There was an error during the export operation. Try simplifying the content and removing images/lists.");
            }
        }


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.
0
Orion
Top achievements
Rank 1
answered on 16 Nov 2018, 05:51 AM
Hi Rumen, I've already implemented to ExportToDocx() method in my application and it's downloading the word document as expected. My requirement is something different, In my I'll be providing a hyperlink (which is associating the word document in location of my server), upon of hyperlink the word document which is associating with the link is being open in the RADEditor using Import command. Then, User can make the changes (using RADEditor ms-word features) and then the changes to be updated in the same location from where I originally imported. To accommodate this, I've been using ExportToDocx(), but this is downloading the file explicitly in the browser, instead of file downloading the changes should be updated in the location where I originally imported. Can we pass the file location as an input to ExportToDocx() method for update the file changes, instead of to windows "Downloads" folder?
0
Rumen
Telerik team
answered on 16 Nov 2018, 11:06 AM
Hello Orion,

The Open option comes from the content-disposition=attachment HTTP header when the file comes from the server. With client-side export, it is up to the browser to decide what options to provide.

What you can do is:

  • check the Save Exported Files article which can help you to save the exported file on the server
  • look into using the OnExportContent to get the file RadEditor provides so you can change it. See this article for details.
  • look into using a different HTML->PDF conversion tool as explained in this section of the documentation. It also links a blog post that shows how you can use the Telerik Document Processing Library for this.


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.
0
Orion
Top achievements
Rank 1
answered on 18 Dec 2018, 07:25 AM

Hi Rumen,
I have referred the Save Exported Files article and used the Page Method. The "storeFile(string base64)" method is not storing any file data in the mentioned file path, but "OnSucceeded(data)" is being called and the data is getting prompted as an alert.

And, I believe the given code should work only for PDF, but I want to store the file as a word document. What are the possible changes to be made for storing as word document? Kindly help me on this.  

0
Orion
Top achievements
Rank 1
answered on 19 Dec 2018, 11:36 AM

Hi Rumen,

"public static string storeFile(string base64)" - This method is not at all invoking when initiate the call from "function callMyPageMethod(arg)" method. Is any other configuration have to be done to make this call? We are completely blocked to move forward on this implementation, can you please help us?

 

 

0
Rumen
Telerik team
answered on 19 Dec 2018, 02:13 PM
Hi,

You can easily save the docx file to the server using this approach:

ASPX:
<form id="form1" runat="server">
    <asp:ScriptManager runat="server" />
    <telerik:RadEditor RenderMode="Lightweight" runat="server" ID="RadEditor1" OnExportContent="RadEditor1_ExportContent">
    </telerik:RadEditor>
    <asp:Button runat="server" ID="Button1" Text="Export to PDF" OnClick="Button1_Click" />
</form>

Codebehind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using Telerik.Web.UI;
 
public partial class Default2 : System.Web.UI.Page
{
     
    protected void RadEditor1_ExportContent(object sender, EditorExportingArgs e)
    {
        string url = String.Format("~/{0}.docx", RadEditor1.ExportSettings.FileName); //set here the path where you want to save the docx file with the contents from RadEditor
        string path = Server.MapPath(url);
 
        if (File.Exists(path))
        {
            File.Delete(path);
        }
 
        using (FileStream fs = File.Create(path))
        {
            Byte[] info = System.Text.Encoding.Default.GetBytes(e.ExportOutput);
            fs.Write(info, 0, info.Length);
        }
 
        e.Cancel = true;
    }
 
    protected void Button1_Click(object sender, EventArgs e)
    {
        RadEditor1.ExportToDocx();
    }
}

You can find attached a sample project attached to my reply.

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.
0
Orion
Top achievements
Rank 1
answered on 24 Dec 2018, 02:39 AM

Thanks Rumen,

I am able to export external images to word but on using the Image Manager to export images to word document it is throwing System.net.web exception at 

byte[] docxBinaryData = docxProvider.Export(flowDocument);

Kindly help me on this.

 

0
Eyup
Telerik team
answered on 27 Dec 2018, 06:06 AM
Hi Orion,

I'm glad the sample provided by my colleague Rumen has proven helpful in saving the document. As for the remaining requirements, I suggest that you open a formal support ticket and send us the modified ExportToDocx.zip sample to demonstrate the specific issue so we can continue providing assistance on this case.

Regards,
Eyup
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.
Tags
General Discussions
Asked by
Orion
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Orion
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or