C# Encoding WebName

Description

Encoding WebName When overridden in a derived class, gets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.

Syntax

Encoding.WebName has the following syntax.


public virtual string WebName { get; }

Example

The following example includes the WebName in an HTML header.


using System;//from   w w w  .  jav  a2 s. c o  m
using System.IO;
using System.Text;
using System.Web;

public class ExampleClass {
      public static void Main(string[] args) 
      {
       Encoding encoding = Encoding.UTF8;
       StreamWriter writer = new StreamWriter("Encoding.html", false, encoding);
           
       writer.WriteLine("<html><head>");
       writer.WriteLine("<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=" +
                               encoding.WebName +"\">");
         writer.WriteLine("</head><body>");
       writer.WriteLine("<p>" + HttpUtility.HtmlEncode(encoding.EncodingName) + "</p>");
       writer.WriteLine("</body></html>");
       writer.Flush();
       writer.Close();
    
         foreach( EncodingInfo ei in Encoding.GetEncodings() )  {
             Encoding e = ei.GetEncoding();
             Console.Write( "{0,-18} ", ei.Name );
             Console.Write( "{0,-18} ", e.WebName );
         }
   }

}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Text »




ASCIIEncoding
Encoding
EncodingInfo
StringBuilder
UnicodeEncoding
UTF8Encoding