Question: Sorry my title must be quite confused. What I want to mean is like this. Let's say, I have total more than 100 html existing files. I want to put this code before end of the head tag. 

```
        <script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

```

I don't want to open every page and insert manually. Because it's lots of file. I tried to do with Find & replace, but it doesn't allow me to add because it's have lots of lines.

So anyway to inject the codes to every page very easily ? 

Please kindly help thanks.

Answer: 
Exception handling is heavy and should be used as a last resort and only for actual exceptions. Try this. It checks for a valid html hex color and then tries named colors. 

```
protected static bool CheckValidFormatHtmlColor(string inputColor)
{
       //regex from http://stackoverflow.com/a/1636354/2343
       if (Regex.Match(inputColor, "^#(?:[0-9a-fA-F]{3}){1,2}$").Success)
           return true;

       var result = System.Drawing.Color.FromName(inputColor);
       return result.IsKnownColor;
}

```
The `Main` method

```cs
static void Main(string[] args)
{
    List<string> testColors = new List<string>
    {
        null
        ,""
        ,"#00"
        ,"#000"
        ,"#12345aa"
        ,"#fff1az"
        ,"#FFDFD991"
        ,"ajdoajsdoijsaod"
    };

    foreach (var color in testColors)
    {
        bool result = IsHtmlColor(color);
        Console.WriteLine($"IsHtmlColor({color}) => {result}");
    }

}

```

The helper method

```cs
public static bool IsHtmlColor(string hexa)
{
    try
    {
        // using System.Windows.Media;
        return ColorConverter.ConvertFromString(hexa) is Color;
    }
    catch
    {
        return false;
    }
}

```