URLEncode a Website Link

For a website URL which contains characters which will be interpreted incorrectly by browsers this needs to be escaped.

URLEncode is used to protect the URL, for example for use in XML, or passing parameters within a querystring.

System.Web.HttpUtility.UrlEncode(link)

I have found the error object reference not set to an instance of an object. To recover this error I found I need to use

HttpUtility.UrlEncode(link)

Indeed its generally a good idea to encode the link, particularly if its comprised of user input data, be it directly from a form, or data which has been added to a database field.