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

No embedded images

3 Answers 161 Views
RichTextEditor
This is a migrated thread and some comments may be shown as answers.
KFC
Top achievements
Rank 1
KFC asked on 13 Dec 2019, 02:32 AM

Hello Experts,

Is there a way to not allow embedded images?

Allow first and remove after is also good but prevent in the first place is good 

Thnx

3 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 16 Dec 2019, 01:56 PM

Hi Khurram,

I am not sure what is the exact requirement. Could you provide us with more information on the specific case? Is your goal to remove the images from an imported document, or you want to prevent the users from inserting images?

I am looking forward to your reply.

Regards,
Martin
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
KFC
Top achievements
Rank 1
answered on 16 Dec 2019, 01:59 PM

Thnx Martin for your reply. Goal is to prevent users copy pasting or inserting images period. All other formatting features should stay but just no image insertion

Thnx

0
Martin
Telerik team
answered on 17 Dec 2019, 09:53 PM

Hello Khurram,

In order to achieve the desired functionality, you could attach to the CommandExecuting event:

this.radRichTextBox.CommandExecuting += this.RadRichTextBox_CommandExecuting;

When handling the event in case the command is of type InsertPictureCommand the event could be canceled, the case with the PasteCommand is a little bit different. You will need to interrupt the paste command to perform some changes before adding the content inside the clipboard of the control.

For more information about ClipboardEx class, you can check the Working With the Content Inside the Clipboard help topic. Please, check the following example:

private void RadRichTextBox_CommandExecuting(object sender, CommandExecutingEventArgs e)
{
	if (e.Command.GetType() == typeof(InsertPictureCommand))
	{
		e.Cancel = true;
	}
	else if (e.Command.GetType() == typeof(PasteCommand))
	{
		e.Cancel = true;

		// Obtain the document inside the clipboard 
		RadDocument document = ClipboardEx.GetDocument().ToDocument();

		// Change it according to your needs 
		document.Selection.SelectAll();
		RadDocumentEditor editor = new RadDocumentEditor(document);
		IEnumerable<ImageInline> images = document.EnumerateChildrenOfType<ImageInline>();
		foreach (var image in images.ToList())
		{
			image.Parent.Children.Remove(image);
		}

		// Insert it in RadRichTextBox 
		this.radRichTextBox.InsertFragment(new DocumentFragment(document));
	}
}

Regards,
Martin
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
RichTextEditor
Asked by
KFC
Top achievements
Rank 1
Answers by
Martin
Telerik team
KFC
Top achievements
Rank 1
Share this question
or