Zip Component, Email Component, Encryption Component ActiveX Control for Zip Compression .NET Components for ASP.NET
ActiveX and .NET Components for Zip Compression, Encryption, Email, XML, S/MIME, HTML Email, Character Encoding, Digital Certificates, FTP, and more ASP Email ActiveX Component


Index of Chilkat Blog Posts

March 13, 2008

VB.NET to Extract Files from MIME

This VB.NET sample recursively traverses a MIME document and saves the embedded files to the filesystem.

    Private Sub TraverseMime(ByVal mime As Chilkat.Mime)
	
        If (mime.NumParts > 0) Then
            Dim i As Integer
            For i = 0 To mime.NumParts - 1
                Dim child As Chilkat.Mime
                child = mime.GetPart(i)
                TraverseMime(child)
            Next
        Else
            If (mime.Filename.Length > 0) Then
                Dim success As Boolean
                If (mime.ContentType.Equals("application/pdf")) Then
                    success = mime.SaveBody("pdfFiles/" & mime.Filename)
                ElseIf (mime.ContentType.Equals("text/xml")) Then
                    success = mime.SaveBody("xmlFiles/" & mime.Filename)
                Else
                    success = mime.SaveBody("otherFiles/" & mime.Filename)
                End If
                If (Not success) Then
                    MessageBox.Show(mime.LastErrorText)
                End If
            End If
        End If
    End Sub
	
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
	
        Dim mime As New Chilkat.Mime()
	
        Dim success As Boolean
        success = mime.UnlockComponent("Anything for 30-day trial")
        If (success = False) Then
            MsgBox("Failed to unlock component")
            Exit Sub
        End If
	
        '  Load a MIME document from a file:
        success = mime.LoadMimeFile("testMime.txt")
        If (success = False) Then
            MsgBox(mime.LastErrorText)
            Exit Sub
        End If
	
        TraverseMime(mime)
	
    End Sub


Privacy Statement. Copyright 2000-2011 Chilkat Software, Inc. All rights reserved.
Send feedback to support@chilkatsoft.com

Components for Microsoft Windows XP, 2000, 2003 Server, Vista, Windows 7, and Windows 95/98/NT4.