Link to home
Start Free TrialLog in
Avatar of aonecomputers
aonecomputers

asked on

vb express 2010 html decode

Trying to use the built in html decoder but it doesn't seem to work in vb express 2010
Many examples on the web but can't get to work.
here is an example from microsoft
Imports System
Imports System.Web
Imports System.IO

Class MyNewClass
   Public Shared Sub Main()
      Dim myString As String
      Dim myWriter As New StringWriter()
      ' Decode the encoded string.
      HttpUtility.HtmlDecode(myString, myWriter)
        End Sub 'Main
End Class 'MyNewClass


the httpUtility gives an error that it is not declared
Avatar of Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger)
Flag of Canada image

Nothing was initialized.

First, you try to decode a String that has nothing in it.

Second, you need to decide where you want to send the result. The StringWriter is an object not often used, and it sends its output to a StringBuilder, an object that you have to learn to use.

You might want to send to a StreamWriter instead, which woud send the information to a file.
Dim myString As String
Dim myWriter = New System.IO.StreamWriter("YourFile.txt")

MyString="your encoded String"
HttpUtility.HtmlDecode(myString, myWriter)
myWriter.Close()

Open in new window

If you want to decode a string and have the result also in a String, you should use another form of the HttpUtility.Decode:
Dim myString As String
Dim decodedStrins as String

myString="your encoded String"
decodedString=HttpUtility.HtmlDecode(MyString)

Open in new window

Avatar of aonecomputers
aonecomputers

ASKER

Sorry I just tried to simplify the code without having code not related to the problem. The error is in the declaration of the HttpUtility.HtmlDecode not in any of the stuff you are referring to. Did you actually get the code you posted to work in VB express 2010 w/o a declaration error?
I tried and after I corrected your typo got the same error Error HttpUtility' is not declared. It may be inaccessible due to its protection level.
Could you post the exact error message. It would be very surprised if it was HttpUtility that is not declared, since you do not have to declare it to use HtmlDecode.

That is why, if you read my answer carefully, I am pointing to the fact that First, you try to decode a String that has nothing in it.

There is nothing in myString, so the decoder has nothing to work with when you call the method. I suspect that the thing that is not declared is myString, not HttpUtility.

The exact error is Error HttpUtility' is not declared. It may be inaccessible due to its protection level.
This is not a run time error. It is highlighted immediately in the editor.
You probably did not reference the dll.

If you call help on HttpUtility, it tells you that this class is in the System.Web.dll.

In order to use that dll, you need to tell Visual Studio that you want to work with it. This is called a reference.

You add a reference through Project...Add Reference. Select the .NET tab, go down to System.Web and click OK.

From then on, your project can use the classes in the dll, including HttpUtility.

Most of the examples you find on the web for that class are assuming that you are in a Web application. This dll is referenced automatically when you create a Web application. It is not in many other types of projects, and you need to reference it manually in order to use it.
I will check that out and let you know. I thought the Imports system.web did that.
There isn't one exactly like that. There is System.Web.ApplicaionServices and System.Web.Services but there doesn't seem to be any way to select them they are just displayed. I did highlight one at a time and click OK but if I go back everything in the list is exactly the same. I
I guess you don't have vb express. What are you using as a base of reference?
I have attached a picture of it below and you can see the actual code to the left. User generated image
ASKER CERTIFIED SOLUTION
Avatar of Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger)
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This did have web developer. The procedure you gave about changing to .net framework 4 instead of the client profile did it. No idea how this got set to begin with but doing that gave the system.web in the add reference and clicking it took some time as opposed to before clicking any of the stuff didn't seem to do anything.
Thanks