System.Web Namespace HttpServerUtility Class
Decodes an HTML-encoded string and returns the decoded string.
[ VB ]
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;
- s
- The HTML string to decode.
The decoded text.
URL encoding ensures that all browsers will correctly transmitted text in URL strings. Characters such as "?", "&", "/", and spaces may be truncated or corrupted by some browsers so those characters cannot be used in ASP.NET pages in "<A>" tags or in querystrings where the strings may be sent by a browser in a request string.
HtmlDecode decodes text that has been transmitted to the server.
The following example contains the function LoadDecodedFile which decodes the data from a file and copies it into one string.
[ VB ]
<%@ 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>
HttpServerUtility Members HttpServerUtility.HtmlDecode Overload List