Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9230517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:50:41+00:00 2026-06-18T05:50:41+00:00

I am displaying an incoming e-mail in a WebBrowser control. If the email is

  • 0

I am displaying an incoming e-mail in a WebBrowser control. If the email is in HTML, links are clickable and users are able to navigate to the URL quickly in their default browser. If the email is in Plain Text, however, I’m simply setting the WebBrowser’s InnerText equal to the text of the email.

This leaves me with URLs that do not have anchor tags, and users have to copy and paste the URL into their browsers.

My first instinct was just to set the InnerHTML to the email text, use a regex to find any URLs and replace the matches with the same thing but with anchor tags.

This presented the problem of removing all line breaks, so I just replaced those with the appropriate tag.

public static string CheckPlainTextLinks(string html)
{
  Regex regx = new Regex(@"((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)", RegexOptions.IgnoreCase);
  MatchCollection mactches = regx.Matches(html);

  foreach (Match match in mactches)
  {
    html = html.Replace(match.Value, "<a href='" + match.Value + "'>" + match.Value + "</a>");
  }

  html = html.Replace(Environment.NewLine, "<br />");

  return html;
}

This is the entirety of my function to scan the text and add links. I then set the InnerHTML of my webBrowser control to what is returned by this function. Unfortunately, the program started getting OutOfMemory Exceptions that went away when my call to this function was taken out.

I looked into using mshtml to create the links instead of changing the html directly with help from these posts, http://social.msdn.microsoft.com/Forums/da-DK/csharpgeneral/thread/1d050260-3625-42cc-94ec-59bba0651a1c. I’m just not sure how to create the IHTMLTxtRange on each of the regex matches.

Is there a better way to create these links or a solution to the out of memory exception?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:50:43+00:00Added an answer on June 18, 2026 at 5:50 am

    Would this work better for you?

    public static string CheckPlainTextLinks(string html) {
        var regx=new Regex(@"((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)", RegexOptions.IgnoreCase);
        return regx.Replace(html, x => "<a href='"+x.Value+"'>"+x.Value+"</a>").Replace(Environment.NewLine, "<br />");
    }
    

    Instead of repeatly replace in a foreach loop, this works with MatchEvaluator.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having difficulties displaying data in a UITextView in iPhone programming. I'm analyzing incoming
displaying html problem with php & mysql Hi basically i have a quick mysql_fetch_array
How can I listen for incoming email and, if it matches a particular profile
I am displaying calendar using calendar control. Each date is displayed as Link button.
I am manually displaying a System.Windows.Forms.Tooltip on a control using the show method, but
I have a WebView displaying a HTML page, linking to a CSS file. The
I displaying 20 rows of content in a page and i am able to
I´m displaying images in a ListBox and i want to control the size (small,
Displaying Type here to ... until the user enters text into a TextBox is
When displaying all articles of a specific month (given through the urls like this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.