Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpUtility.UrlEncode in console application

I'd like to use HttpUtility.UrlEncode in a console application, VB.NET, VS 2010 Beta 2.

System.Web.HttpUtility.UrlEncode(item) 

Error message: 'HttpUtility' is not a member of 'Web'.

In this question Anjisan suggests to add a reference to System.Web, as follows:

  1. In your solution explorer, right click on references
  2. Choose "add reference"
  3. In the "Add Reference" dialog box, use the .NET tab
  4. Scroll down to System.Web, select that, and hit ok

However, I don't have a System.Web entry at that location.

like image 739
George Avatar asked Jan 27 '10 11:01

George


People also ask

How do I use HttpUtility UrlEncode?

The HttpUtility. UrlEncode method uses UTF-8 encoding by default. Therefore, using the UrlEncode method provides the same results as using the UrlEncode method and specifying UTF8 as the second parameter. UrlEncode is a convenient way to access the UrlEncode method at run time from an ASP.NET application.

What does HttpUtility UrlEncode do?

HttpUtility.UrlEncode Method (System.Web)Encodes a URL string. These method overloads can be used to encode the entire URL, including query-string values. To encode or decode values outside of a web application, use the WebUtility class.


2 Answers

System.Web is there, but seems Visual Studio doesn't sort by name by default. You'll need to click Component name column to get that list sorted.

I was able to run this code:

Console.WriteLine(System.Web.HttpUtility.UrlEncode(" ")); // + 

Just adding a System.Web reference, without System.Web.Extensions.

Also, You should replace your target framework from .NET Framework 4 Client Profile to .NET Framework 4; go to Project >> Properties... >> Application tab

like image 148
Rubens Farias Avatar answered Sep 22 '22 11:09

Rubens Farias


Make sure your target framework is ".NET Framework 4" not ".NET Framework 4 Client Profile".

like image 26
Rush Frisby Avatar answered Sep 20 '22 11:09

Rush Frisby