Sample code for 30+ languages & platforms
VB.NET

Set a MIME Body, Preserving Content Headers

See more MIME Examples

Demonstrates the Chilkat Mime.SetBody method, which sets the current part's body while preserving the existing content headers (Content-Type, charset, Content-Transfer-Encoding). The only argument is the body text; it is a void method.

Background: Unlike the SetBodyFrom... methods, which set both the content and the headers that describe it, SetBody replaces only the body text and leaves the existing Content-Type and encoding in place. That is what you want when the media type is already correct and you simply need to swap in new content — updating a templated part, for instance — without re-declaring its type.

Chilkat VB.NET Downloads

VB.NET
Dim success As Boolean = False

'  Demonstrates the Mime.SetBody method, which sets the current part's body while preserving the
'  existing content headers (Content-Type, charset, Content-Transfer-Encoding).  The only argument
'  is the body text.  It is a void method.

Dim mime As New Chilkat.Mime

'  Establish the content headers first.
success = mime.SetBodyFromPlainText("initial")
If (success = False) Then
    Debug.WriteLine(mime.LastErrorText)
    Exit Sub
End If


'  Replace just the body text, keeping the existing Content-Type and encoding.
mime.SetBody("This is the replacement body text.")

Dim mimeText As String = mime.GetMime()
If (mime.LastMethodSuccess = False) Then
    Debug.WriteLine(mime.LastErrorText)
    Exit Sub
End If

Debug.WriteLine(mimeText)