No embedded images

4 posts, 0 answers
  1. KFC
    KFC avatar
    5 posts
    Member since:
    Dec 2012

    Posted 12 Dec 2019 Link to this post

    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

  2. Martin
    Admin
    Martin avatar
    90 posts

    Posted 16 Dec 2019 Link to this post

    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.
  3. KFC
    KFC avatar
    5 posts
    Member since:
    Dec 2012

    Posted 16 Dec 2019 in reply to Martin Link to this post

    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

  4. Martin
    Admin
    Martin avatar
    90 posts

    Posted 17 Dec 2019 Link to this post

    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.
Back to Top