Vladimir Potapov
Vladimir Potapov

Reputation: 2437

The name 'HttpUtility' does not exist in the current context (winform)

Iget the following error:

The name 'HttpUtility' does not exist in the current context

I am building a winform app this my code using framework 4 client profile and I can't find the System.Web reference:

string longurl = "https://test.com/currentaccount/Pages/current.aspx";
                        var uriBuilder = new UriBuilder(longurl);
                        var query = HttpUtility.ParseQueryString(uriBuilder.Query);//error
                        query["ltFrom"] = FromDate;
                        query["ltTo"] = ToDate;
                        query["ltFilterSelected"] = "none";
                        uriBuilder.Query = query.ToString();
                        longurl = uriBuilder.ToString();

What is the problem?

Upvotes: 3

Views: 10074

Answers (4)

Kaustubh Pandey
Kaustubh Pandey

Reputation: 31

to use "HttpUtility" simply add reference in visual studio from option Project->Add Reference->click on system.web then ok.

Upvotes: 2

Vijay Singh Rana
Vijay Singh Rana

Reputation: 1100

The project is set on Target Framework to: .net 4 client profile.

That's the problem. HttpUtility doesn't exist in the client profile. Target the full profile instead (and make sure you have a reference to System.Web.dll).

Compare the "Version information" line from the above documentation:

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

with that of (say) System.String:

.

NET Framework
Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0
.NET Framework Client Profile
Supported in: 4, 3.5 SP1
Portable Class Library
Supported in: Portable Class Library
.NET for Windows Store apps
Supported in: Windows 8

ref: Im getting error on visual studio 2010: The type or namespace name 'HttpUtility' does not exist

Upvotes: 3

Trevor Pilley
Trevor Pilley

Reputation: 16423

HttpUtility is based in System.Web, the Client Profile for .NET 4 only allows access to a subset of the .NET framework and System.Web is not included in that.

If you can, change from Client Profile to Full unless you have a really good reason to stick with Client Profile in which case you will need to find a different approach.

Upvotes: 1

igofed
igofed

Reputation: 1442

HttpUtility cannot be accepted with ClientProfile - change your .Net version to full.

Upvotes: 4

Related Questions