Encoding.BodyName Property Home
This page is specific to:.NET Framework Version:1.12.03.03.54.0
Encoding.BodyName Property
When overridden in a derived class, gets a name for the current encoding that can be used with mail agent body tags.

Namespace: System.Text
Assembly: mscorlib (in mscorlib.dll)

Syntax

'Usage

Dim instance As Encoding
Dim value As String

value = instance.BodyName


'Declaration

Public Overridable ReadOnly Property BodyName As String
/** @property */
public String get_BodyName ()

Not applicable.

Property Value

A name for the current Encoding that can be used with mail agent body tags. -or- An empty string (""), if the current Encoding cannot be used.
Remarks

If your application needs an encoding for a body name, it should call GetEncoding with the BodyName property. Often the method retrieves a different encoding from the test encoding furnished in the call. Generally only e-mail applications need to retrieve such an encoding.

Example

The following code example encodes a string using UTF-7 before writing it to a stream.

Imports System
Imports System.IO
Imports System.Text
Imports Microsoft.VisualBasic

Namespace UTF7Example
    Public Class UTF7ExampleClass
        Public Shared Sub Main()
            Dim unicodeString As String = "This string contains the unicode character Pi(" & ChrW(&H03A0) & ")"

            ' Create a UTF7 encoding
            Dim utf7 As Encoding = Encoding.UTF7

            ' Converting to UTF7 encodes characters so that they will pass through
            ' ASCII systems such as email.
            Dim utf7Writer As New StreamWriter("output.txt", False, utf7)
            utf7Writer.WriteLine(utf7.BodyName)
            utf7Writer.WriteLine(unicodeString)
            utf7Writer.Flush()
            utf7Writer.Close()
        End Sub
    End Class
End Namespace

package UTF7Example; 

import System.*;
import System.IO.*;
import System.Text.*;

public class UTF7ExampleClass
{
    public static void main(String[] args)
    {
        String unicodeString = 
            "This string contains the unicode character Pi(\u03a0)";

        // Create a UTF7 encoding
        Encoding utf7 = Encoding.get_UTF7();
        // Converting to UTF7 encodes characters so that they will pass through
        // ASCII systems such as email.
        StreamWriter utf7Writer = new StreamWriter("output.txt", false, utf7);
        utf7Writer.WriteLine(utf7.get_BodyName());
        utf7Writer.WriteLine(unicodeString);
        utf7Writer.Flush();
        utf7Writer.Close();
    } //main
} //UTF7ExampleClass

The following code example retrieves the different names for each encoding and displays the encodings with one or more names that are different from EncodingInfo.Name. It displays EncodingName but does not compare against it.

Imports System
Imports System.Text

Public Class SamplesEncoding   

   Public Shared Sub Main()

      ' Print the header.
      Console.Write("Name               ")
      Console.Write("CodePage  ")
      Console.Write("BodyName           ")
      Console.Write("HeaderName         ")
      Console.Write("WebName            ")
      Console.WriteLine("Encoding.EncodingName")

      ' For every encoding, compare the name properties with EncodingInfo.Name.
      ' Display only the encodings that have one or more different names.
      Dim ei As EncodingInfo
      For Each ei In  Encoding.GetEncodings()
         Dim e As Encoding = ei.GetEncoding()
         
         If ei.Name <> e.BodyName OrElse ei.Name <> e.HeaderName OrElse ei.Name <> e.WebName Then
            Console.Write("{0,-18} ", ei.Name)
            Console.Write("{0,-9} ",  e.CodePage)
            Console.Write("{0,-18} ", e.BodyName)
            Console.Write("{0,-18} ", e.HeaderName)
            Console.Write("{0,-18} ", e.WebName)
            Console.WriteLine("{0} ", e.EncodingName)
         End If

      Next ei 

   End Sub 'Main

End Class 'SamplesEncoding 


'This code produces the following output.
'
'Name               CodePage  BodyName           HeaderName         WebName            Encoding.EncodingName
'shift_jis          932       iso-2022-jp        iso-2022-jp        shift_jis          Japanese (Shift-JIS)
'windows-1250       1250      iso-8859-2         windows-1250       windows-1250       Central European (Windows)
'windows-1251       1251      koi8-r             windows-1251       windows-1251       Cyrillic (Windows)
'Windows-1252       1252      iso-8859-1         Windows-1252       Windows-1252       Western European (Windows)
'windows-1253       1253      iso-8859-7         windows-1253       windows-1253       Greek (Windows)
'windows-1254       1254      iso-8859-9         windows-1254       windows-1254       Turkish (Windows)
'csISO2022JP        50221     iso-2022-jp        iso-2022-jp        csISO2022JP        Japanese (JIS-Allow 1 byte Kana)
'iso-2022-kr        50225     iso-2022-kr        euc-kr             iso-2022-kr        Korean (ISO)


import System.*;
import System.Text.*;

public class SamplesEncoding
{
    public static void main(String[] args)
    {
        // Print the header.
        Console.Write("Name               ");
        Console.Write("CodePage  ");
        Console.Write("BodyName           ");
        Console.Write("HeaderName         ");
        Console.Write("WebName            ");
        Console.WriteLine("Encoding.EncodingName");
        EncodingInfo ei[] = Encoding.GetEncodings();
        for(int iCtr = 0; iCtr < ei.length; iCtr++) {
            Encoding e = ei[iCtr].GetEncoding();
            if(!(ei[iCtr].get_Name().equalsIgnoreCase(e.get_BodyName())) 
                || !(ei[iCtr].get_Name().equalsIgnoreCase(e.get_HeaderName()))
                || !(ei[iCtr].get_Name().equalsIgnoreCase(e.get_WebName()))) {
                Console.Write("{0,-18} ", ei[iCtr].get_Name());
                Console.Write("{0,-9} ", String.valueOf(e.get_CodePage()));
                Console.Write("{0,-18} ", e.get_BodyName());
                Console.Write("{0,-18} ", e.get_HeaderName());
                Console.Write("{0,-18} ", e.get_WebName());
                Console.WriteLine("{0} ", e.get_EncodingName());
            }
        }
    } //main
} //SamplesEncoding

/* 
This code produces the following output.

Name               CodePage  BodyName           HeaderName         WebName  
          Encoding.EncodingName
shift_jis          932       iso-2022-jp        iso-2022-jp        shift_jis 
         Japanese (Shift-JIS)
windows-1250       1250      iso-8859-2         windows-1250       windows-1250 
      Central European (Windows)
windows-1251       1251      koi8-r             windows-1251       windows-1251 
      Cyrillic (Windows)
Windows-1252       1252      iso-8859-1         Windows-1252       Windows-1252 
      Western European (Windows)
windows-1253       1253      iso-8859-7         windows-1253       windows-1253  
     Greek (Windows)
windows-1254       1254      iso-8859-9         windows-1254       windows-1254 
      Turkish (Windows)
csISO2022JP        50221     iso-2022-jp        iso-2022-jp        csISO2022JP  
      Japanese (JIS-Allow 1 byte Kana)
iso-2022-kr        50225     iso-2022-kr        euc-kr             iso-2022-kr 
       Korean (ISO)

*/


Platforms

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

Version Information

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
See Also

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View