Save attachment as another file.
[Syntax] C++: HRESULT SaveAttachmentAs( BSTR sFile, int nCount, long* pVal ) Visual Basic: SaveAttachmentAs( sFile As String, nCount As Integer ) As long C#: long SaveAttachmentAs( string sFile, int nCount )
Parameters
sFile
Name of the new file to be saved.
nCount
Ordinal number of file attachment. The minimum value is 1, the maximum value is returned by method GetAttachmentCount.
Return Value
If this method succeeds, the return value is zero. If it fails, the return value is non-zero.
Remarks
If the target directory does not exist, this method fails.
Usage Example
[C#]
public void ParseAttachments( string emailFile )
{
int i = 0, nRet = 0, nCount = 0, nSize;
string tempFolder = "c:\\temp_attachments", fileName = "", newName = "";
POPMSGClass oMsg = new POPMSGClass();
try
{
nRet = oMsg.ImportFile( emailFile );
if( nRet != 0 )
throw new Exception( "error with ImportFile" );
if( oMsg.CreateFolder( tempFolder )!= 0 )
throw new Exception( "error with Create temporary folder" );
nCount = oMsg.GetAttachmentCount(); //get total count of attachments
for( i = 1; i <= nCount; i++ )
{
fileName = oMsg.GetAttachmentName(i); //get attachment name
newName = tempFolder;
newName += "\\new_";
newName += fileName; //generate a new file name
//save attachment to temporary directory
if( oMsg.SaveAttachmentAs( fullName, i ) != 0 )
throw new Exception( "error with SaveAttachmentAs" );
}
}
catch( Exception e )
{
Console.WriteLine( e.Message );
}
oMsg = null;
}
See Also
SaveAttachment Method
GetAttachmentCount Method
GetAttachmentChunk Method
GetAttachmentSize Method
GetAttachmentName Method
2001-2007 © Copyright AdminSystem Software Limited. All rights reserved.