The type or namespace name 'Server' could not be found (are you missing a using directive or an assembly reference?)

I use "Server.UrlEncode" in my class, I also have the

using System.Web

directive. How can this sucker not be found?
RichardFoxAsked:
Who is Participating?
 
AerosSagaCommented:
At the top of your class like so:

Imports System.Web.HttpServerUtility
Imports System.Security.Principal
Public Class _Default

Regards,

Aeros
0
 
AerosSagaCommented:
did you import the system.web namespace?
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
AerosSagaCommented:
if not try using system.web.httpserverutility.urlencode
0
 
RichardFoxAuthor Commented:
AerosSaga, when you ask did I import the namespace, what do you mean? I thought the "using" directive was all I needed
0
 
ihenryCommented:

Is this compile or run-time error?

Server is a property of System.Web.UI.Page class which is a shortcut to instance of HttpServerUtility class. You shouldn't be able to make a method call like "Server.UrlEncode" if your class is not System.Web.UI.Page or inherits from that class. If that is the case use HttpServerUtility.UrlEncode() instead.

Page.Server Property
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWebUIPageClassServerTopic.asp

HttpServerUtility.UrlEncode Method
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWebHttpServerUtilityClassUrlEncodeTopic.asp


HTH
0
 
RichardFoxAuthor Commented:
Thanks folks, what really puzzled me was that i could call Server.UrlEncode in my Page_Load function (where the class is a child of System.Web.UI.Page), but not in another class which I defined myself. So I came to the same conclusion which jhenry spelled out, and qualified the UrlEncode function with System.Web.HttpUtility.UrlEncode()

THanks for the help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.