roykasa
roykasa

Reputation: 3027

error CS0103: The name `HttpUtility' does not exist in the current context

I get this error "error CS0103: The name `HttpUtility' does not exist in the current context" when i try to compile my c# file using "$ mcs file.cs". I have added "using System.Web" and i am running this on Suse 12.1 using the mono framework. I am new to C# and am following the tutorial here http://www.codeproject.com/Articles/9407/Introduction-to-Mono-Your-first-Mono-app

this is the code within my file.cs

using System;
using System.Net;
using System.Web;
using System.Text;
using System.Text.RegularExpressions;

namespace Dela.Mono.Examples
{
        class GoogleSearch
         {
                static void Main(string[] args)
                 {
                        Console.Write("Please enter a string to search google for:");
                        string searchString = HttpUtility.UrlEncode(Console.ReadLine());

                        Console.WriteLine();
                        Console.Write("Please wait....\r");

                        //Query google
                        WebClient webClient = new WebClient();
                        byte[] response =     webClient.DownloadData("http://www.google.com/search?&num=5&q=" + searchString);


                        //Check reponse results
                        string regex = "g><a\\shref=\"?(?<URL>[^\">]*)[^>]*>(?<Name>[^<]*)";
                        MatchCollection matches = Regex.Matches(Encoding.ASCII.GetString(response), regex);

                        //output results
                        Console.WriteLine("===== Results =====");
                                 if(matches.Count > 0)
                                 {
                                        foreach(Match match in matches)
                                        {
                                                 Console.WriteLine(HttpUtility.HtmlDecode(
                                                        match.Groups["Name"].Value) +
                                                        " - " + match.Groups["URL"].Value);
                                        }
                                 }
                                 else
                                 {
                                        Console.WriteLine("0 results found");
                                 }
                } 
        }
}

What could be the problem and how to i resolve this?

Upvotes: 0

Views: 3935

Answers (1)

Nasreddine
Nasreddine

Reputation: 37788

As stated in the article you linked to, try compiling with :

$ mcs file.cs -r System.Web.dll

Upvotes: 1

Related Questions