Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

vb express 2010 html decode

Posted on 2011-09-17
9
Medium Priority
?
862 Views
Last Modified: 2012-05-12
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
0
Comment
Question by:aonecomputers
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 40
ID: 36555625
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

0
 

Author Comment

by:aonecomputers
ID: 36557123
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.
0
 
LVL 40
ID: 36557429
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.

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:aonecomputers
ID: 36557760
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.
0
 
LVL 40
ID: 36557913
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.
0
 

Author Comment

by:aonecomputers
ID: 36558091
I will check that out and let you know. I thought the Imports system.web did that.
0
 

Author Comment

by:aonecomputers
ID: 36558117
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. add reference
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 36558269
Imports is not sufficient.

You set the reference first. Then you could optionnally use Imports.

The use of Imports is only to simplify your code. Once you have an Imports, you do not have to type the namespace each time you call a class or a constant. That is all that Imports do. It's akind to the Path environment variable for directories if you know the concept.

Imports does nothing if the reference is not set.

The reference you need is System.Web, no more. The one you have in your screen shot are only extensions of System.Web. They do not contain the basics.

The probable reason why you do not see System.Web is that you have targeted the Framework 4 Client Profile as shown at the top of your screen shot. This is a subset of the framework that does not contain everything. And according to the documentation, System.Web is not supported in the shortened version you are targeting.

You can change it by going into the projects properties: Project...<Project name> Properties...Compile Tab...Advanced Compile Options button...Target Framework. You should reference .NET Framework 4, not the Client Profile to have access to System.Web.

If you still do not see System.Web in the references after that, it can be for 2 more reasons:

- The list does not always sort properly. Clicking on the header of the column usually correct the problem, but not always. You might have to scroll until you find System.Web.

- If you have installed only Visual Basic Express, you do not have everything. Most web components come with Visual Web Developer Express. If you install it, it will merge with your installation of Visual Basic without causing any problem. You will simply have more choices when you create a new project, and more classes to work with. I have a complete installation, so I cannot tell you if VB alone has System.Web, but I would bet it does not. You might also install Visual Studio Express instead. It includes both as well as a few other languages and tools to develop applications for Windows Phone.

0
 

Author Closing Comment

by:aonecomputers
ID: 36562722
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
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question