ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Retrieve only image tag from TinyMCE editor in ASP.Net using RegularExpression in C# and VB.Net<p>You cannot hide all the tag forTinyMCE Editor. But you can get only image tag content onces you are saving the content.</p> <h1 class="header"><a title="RichTextBox Example using Free TinyMCE Editor in ASP.Net'a" href="https://www.aspsnippets.com/Articles/RichTextBox-Example-using-Free-TinyMCE-Editor-in-ASPNet.aspx">RichTextBox Example using Free TinyMCE Editor in ASP.Net</a></h1> <p>Refer the below sample code for your reference.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;html xmlns=&#34;http://www.w3.org/1999/xhtml&#34;&gt; &lt;head runat=&#34;server&#34;&gt; &lt;title&gt;TinyMCE ASP.Net Example&lt;/title&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;tinymce/jscripts/tiny_mce/tiny_mce.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; tinyMCE.init({ mode: &#34;textareas&#34;, theme: &#34;advanced&#34;, plugins: &#34;safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,imagemanager,filemanager&#34;, theme_advanced_buttons2: &#34;image&#34;, theme_advanced_toolbar_location: &#34;top&#34;, theme_advanced_toolbar_align: &#34;left&#34;, }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form id=&#34;form1&#34; runat=&#34;server&#34;&gt; &lt;div&gt; &lt;asp:TextBox ID=&#34;RichTextBox&#34; runat=&#34;server&#34; TextMode=&#34;MultiLine&#34;&gt;&lt;/asp:TextBox&gt; &lt;asp:Button ID=&#34;btnSave&#34; runat=&#34;server&#34; Text=&#34;Save&#34; OnClick=&#34;btnSave_Click&#34; /&gt; &lt;asp:Label ID=&#34;lblDisplay&#34; runat=&#34;server&#34; Text=&#34;&#34;&gt;&lt;/asp:Label&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt;</pre> <p><span style="text-decoration: underline;"><strong>C#</strong></span></p> <pre class="brush: csharp">protected void btnSave_Click(object sender, EventArgs e) { lblDisplay.Visible = true; RichTextBox.Visible = false; List&lt;string&gt; imagestring = GetImagesInHTMLString(RichTextBox.Text); foreach (string imagetag in imagestring) { lblDisplay.Text += imagetag + &#34;&lt;br/&gt;&#34;; } } private List&lt;string&gt; GetImagesInHTMLString(string htmlString) { List&lt;string&gt; images = new List&lt;string&gt;(); string pattern = @&#34;&lt;(img)\b[^&gt;]*&gt;&#34;; Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase); MatchCollection matches = rgx.Matches(htmlString); for (int i = 0, i&lt; matches.Count;i++) { images.Add(matches[i].Value); } return images; }</pre> <p><span style="text-decoration: underline;"><strong>VB.Net</strong></span></p> <pre class="brush: vb">Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) lblDisplay.Visible = True RichTextBox.Visible = False Dim imagestring As List(Of String) = GetImagesInHTMLString(RichTextBox.Text) For Each imagetag As String In imagestring lblDisplay.Text += imagetag &amp; "&lt;br/&gt;" Next End Sub Private Function GetImagesInHTMLString(ByVal htmlString As String) As List(Of String) Dim images As List(Of String) = New List(Of String)() Dim pattern As String = "&lt;(img)\b[^&gt;]*&gt;" Dim rgx As Regex = New Regex(pattern, RegexOptions.IgnoreCase) Dim matches As MatchCollection = rgx.Matches(htmlString) Dim i As Integer = 0 Do While (i &lt; matches.Count) &nbsp;&nbsp; images.Add(matches(i).Value) &nbsp;&nbsp; i = (i + 1) Loop Return images End Function </pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><span style="text-decoration: underline;"><strong><img src="https://i.imgur.com/xwqibcf.gif" alt="" width="472" height="380" /></strong></span></p> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/144897/Retrieve-only-image-tag-from-TinyMCE-editor-in-ASPNet-using-RegularExpression-in-C-and-VBNet/https://www.aspforums.net:443/Threads/144897/Retrieve-only-image-tag-from-TinyMCE-editor-in-ASPNet-using-RegularExpression-in-C-and-VBNet/Mon, 26 Feb 2018 06:47:49 GMT