Attachment.SaveAs Method


Saves the attachment to a local file.

[Visual Basic]
Public Sub SaveAs( _
    fileName As String, _
    overwrite As Boolean _
)
[C#]
public void SaveAs(
    string fileName,
    bool overwrite
);
[C++]
public: void SaveAs(
    String^ fileName,
    bool overwrite
);
[JScript]
public function SaveAs( 
    fileName : String
    overwrite : Boolean
);

Parameters

fileName
The file name to save.
overwrite
A boolean value indicates whether this method overwrites the file if the file is existed.

Example

[Visual Basic, C#, C++, JScript.NET] To get the full samples of EAGetMail, please refer to Samples section.

[Visual Basic - Parse Attachment]
Imports EAGetMail

Public Sub ParseAttachment()
    Dim oMail As New Mail("TryIt")
    oMail.Load("c:\test.eml", False)

    ' Decode winmail.dat (TNEF) automatically
    oMail.DecodeTNEF()

    Dim atts() As Attachment = oMail.Attachments
    
    Dim tempFolder As String = "c:\temp"
    Dim count As Integer = atts.Length
    If (Not System.IO.Directory.Exists(tempFolder)) Then
        System.IO.Directory.CreateDirectory(tempFolder)
    End If

    For i As Integer = 0 To count - 1
        Dim att As Attachment = atts(i)
        Dim attname As String = String.Format("{0}\{1}", tempFolder, att.Name)
        att.SaveAs(attname, True)
    Next
End Sub


[C# - Parse Attachment] using System; using System.Collections; using EAGetMail; public void ParseAttachment() { Mail oMail = new Mail("TryIt"); oMail.Load("c:\\test.eml", false); // Decode winmail.dat (TNEF) automatically oMail.DecodeTNEF(); Attachment [] atts = oMail.Attachments; int count = atts.Length; string tempFolder = "c:\\temp"; if(!System.IO.Directory.Exists(tempFolder)) System.IO.Directory.CreateDirectory(tempFolder); for(int i = 0; i < count; i++) { Attachment att = atts[i]; string attname = String.Format("{0}\\{1}", tempFolder, att.Name); att.SaveAs(attname , true); } }
[C++ - Parse Attachment] using namespace System; using namespace EAGetMail; Void ParseAttachment() { Mail ^oMail = gcnew Mail("TryIt"); oMail->Load("c:\\test.eml", false); // Decode winmail.dat (TNEF) automatically oMail->DecodeTNEF(); array<Attachment^> ^atts= oMail->Attachments; int count = atts->Length; String^ tempFolder = "c:\\temp"; if(!System::IO::Directory::Exists(tempFolder)) System::IO::Directory::CreateDirectory(tempFolder); for(int i = 0; i < count; i++) { Attachment ^att = atts[i]; String ^attname = String::Format("{0}\\{1}", tempFolder, att->Name); att->SaveAs(attname, true); } }
[JScript - Parse Attachment] function ParseAttachment() { var oMail:Mail = new Mail("TryIt"); oMail.Load("c:\\test.eml", false); // Decode winmail.dat (TNEF) automatically oMail.DecodeTNEF(); var atts:Attachment[] = oMail.Attachments; var count:int = atts.Length; var tempFolder:String = "c:\\temp"; if(!System.IO.Directory.Exists(tempFolder)) System.IO.Directory.CreateDirectory(tempFolder); for(var i:int = 0; i < count; i++) { var att:Attachment = atts[i]; var attname:String = String.Format("{0}\\{1}", tempFolder, att.Name); att.SaveAs(attname , true); } }

See Also

Mail.Attachments Property

Online Tutorials

Parse Email in C# - Tutorial
Parse winmail.dat(TNEF) in C# - Tutorial
Parse Email in VB.NET - Tutorial
Parse winmail.dat(TNEF) in VB.NET - Tutorial
Parse Email in C++/CLI - Tutorial
Parse winmail.dat(TNEF) in C++/CLI - Tutorial