This documentation is archived and is not being maintained.

HttpServerUtility.HtmlDecode Method (String)

.NET Framework 1.1

Decodes an HTML-encoded string and returns the decoded string.

[Visual Basic]
Overloads Public Function HtmlDecode( _
   ByVal s As String _
) As String
[C#]
public string HtmlDecode(
 string s
);
[C++]
public: String* HtmlDecode(
 String* s
);
[JScript]
public function HtmlDecode(
   s : String
) : String;

Parameters

s
The HTML string to decode.

Return Value

The decoded text.

Remarks

URL encoding ensures that all browsers will correctly transmit text in URL strings. Characters such as ?, &,/, and spaces may be truncated or corrupted by some browsers so those characters cannot must be encoded in <A> tags or in query strings where the strings may be re-sent by a browser in a request string.

HtmlDecode decodes text that has been transmitted to the server.

Example

[Visual Basic, C#, JScript] The following example contains the function LoadDecodedFile which decodes the data from a file and copies it into one string.

[Visual Basic] 
<%@ PAGE LANGUAGE = VB %>
<%@ IMPORT NAMESPACE = System.IO %>
 
<html>
<script runat = server>
 
   Function LoadDecodedFile(file As String) As String
      Dim DecodedString As String
      Dim fs As New FileStream(file, FileMode.Open)
      Dim r As New StreamReader(fs)
      ' Position the file pointer at the beginning of the file.
      r.BaseStream.Seek(0, SeekOrigin.Begin)
      ' Read the entire file into a string and decode each chunk.
      Do While r.Peek() > -1
         DecodedString = DecodedString & _
            Server.HtmlDecode(r.ReadLine())
      Loop
      r.Close()
      LoadDecodedFile = DecodedString
   End Function
 
</script>
</html>


[C#] 
<%@ PAGE LANGUAGE = C# %>
 <%@ IMPORT NAMESPACE = System.IO %>
 
 <html>
 <script runat = server>
 
    String LoadDecodedFile(String file)
       {
       String DecodedString = "";
       FileStream fs = new FileStream(file, FileMode.Open);
       StreamReader r = new StreamReader(fs);
 
       // Position the file pointer at the beginning of the file.
       r.BaseStream.Seek(0, SeekOrigin.Begin);
       
       // Read the entire file into a string and decode each chunk.  
       while (r.Peek() > -1)
          DecodedString += Server.HtmlDecode(r.ReadLine());
 
       r.Close();
       return DecodedString; 
       }
 
 </script>
 </html>


[JScript] 
<%@ PAGE LANGUAGE = JSCRIPT %>
<%@ IMPORT NAMESPACE = System.IO %>
 
<html>
<script runat = server>
 
   function LoadDecodedFile(file : String) : String{
      var decodedString : String
      var fs : FileStream = new FileStream(file, FileMode.Open)
      var r : StreamReader = new StreamReader(fs)
      // Position the file pointer at the beginning of the file.
      r.BaseStream.Seek(0, SeekOrigin.Begin)
      // Read the entire file into a string and decode each chunk.
      while(r.Peek() > -1){
         decodedString = decodedString + Server.HtmlDecode(r.ReadLine())
      }
      r.Close()
      return decodedString
   }

</script>
</html>

[C++] No example is available for C++. To view a Visual Basic, C#, or JScript example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

HttpServerUtility Class | HttpServerUtility Members | System.Web Namespace | HttpServerUtility.HtmlDecode Overload List

Show: