Share via


FileName Property

FileName Property

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Returns the name of the file containing the message on the file system. This property is read-only.

Applies To

IMessages Interface

Type Library

Microsoft CDO for Exchange 2000 Library

DLL Implemented In

CDOEX.DLL

Syntax

[Visual Basic]Property FileName(var As Variant) As String

[C++]HRESULT get_FileName(VARIANT varBSTRFilename);

Parameters

  • var
    The message you want to determine the file name of.
  • Filename
    The name of the file containing the message on the file system.

Remarks

You can identify the message for which you want the file name using the first argument to the property. You can either specify the ordinal index of the Message object or pass the IMessage object reference itself.

One common use of the FileName property is when you want to modify the contents of the messages stored in a particular directory and save the changes back into the file from which each Message object was derived. When you retrieve a Messages collection, each Message object in the collection is created using the serialized message stream stored in a file with the .eml extension. For these messages, unlike messages stored in the Microsoft Exchange store, you cannot use the IDataSource interface on the Message object to bind to the file, call IDataSource.Save, and thereby save the modified message contents back to the file. In such cases, you must use a Microsoft ActiveX Data Objects (ADO) Stream object or some other means, such as a Scripting.FileSystemObject, to save the new message contents back to the file system. You can use the FileName property to get the file name, and then overwrite the file with the new contents of the message. You can use the IMessage.GetStream method to return the contents of the Message object in serialized format within an ADO Stream object. The _Stream interface defines the _Stream.SaveToFile method that can be used to save the stream to disk. The following example demonstrates how to do this.

Examples

This example appends text to the end of each text/plain body part of each message in the SMTP drop directory, and then saves the modified message back into the file from which the Message object was derived.

[Visual Basic]

Dim iDropDir as New CDO.DropDirectory Dim iMsgs as CDO.IMessages Dim iMsg as CDO.Message Dim iStream as ADODB.Stream Dim fileName as String Dim TxtBody as String

Set iMsgs = iDropDir .GetMessages For Each iMsg in iMsgs TxtBody = "" fileName = "" fileName = iMsgs.FileName(iMsg) TxtBody = iMsg.TextBody TxtBody = TxtBody & vbCrLf & vbCrLf & "Here is some appended text" iMsg.TextBody = TxtBody Set iStream = iMsg.GetStream iStream.SaveToFile fileName, adSaveCreateOverWrite Next iMsg

[C++]

#import "d:\program files\common files\system\ado\msado15.dll" no_namespace raw_interfaces_only #import <cdosys.dll> no_namespace raw_interfaces_only #include <iostream.h>

void main(int argc, char* argv[]) { CoInitialize(NULL);

IDropDirectory* pDropDir = NULL; IMessages* pMsgs = NULL; IUnknown* pUnk = NULL; IEnumVARIANT* pEnum = NULL;

CoCreateInstance( __uuidof(DropDirectory), NULL, CLSCTX_SERVER, __uuidof(IDropDirectory), (void**)&pDropDir));

pDropDir->GetMessages(L"",&pMsgs); long count = 0; pMsgs->get_Count(&count); cout << count << endl;

pMsgs->get__NewEnum(&pUnk); pUnk->QueryInterface(__uuidof(IEnumVARIANT),(void**)&pEnum));

ULONG cFetched = 0; VARIANT var; VariantInit(&var); while (1) { cFetched = 0; pEnum->Next(1,&var,&cFetched); cout << "fetched: " << cFetched << endl; if(cFetched == 0) break; IMessage* pMsg = NULL; var.pdispVal->QueryInterface(__uuidof(IMessage),(void**)&pMsg); var.pdispVal->Release(); VariantClear(&var);

  // get file name
  BSTR szFilename;
  VARIANT varIntf;
  VariantInit(&amp;varIntf);
  V_VT(&amp;varIntf) = VT_DISPATCH;
  varIntf.pdispVal = pMsg;
  varIntf.pdispVal-&gt;AddRef();
  pMsgs-&gt;get_Filename(varIntf,&amp;szFilename);

  // get text body of message
  BSTR szTxtBody;
  pMsg-&gt;get_TextBody(&amp;szTxtBody);
  _bstr_t tempBody(szTxtBody);
  tempBody += "\r\n\r\nThis is some appended text";
  pMsg-&gt;put_TextBody(BSTR(tempBody);
  SysFreeString(szTxtBody);

  _Stream* pStrm = NULL;
  pMsg-&gt;GetStream(&amp;pStrm);
  // write changes back to file
  pStrm-&gt;SaveToFile(szFilename,adSaveCreateOverWrite);
  pStrm-&gt;Release();
  SysFreeString(szFilename);
  pMsg-&gt;Release();
}

CoUninitialize(); }

Send us your feedback about the Microsoft Exchange Server 2003 SDK.

Build: June 2007 (2007.618.1)

© 2003-2006 Microsoft Corporation. All rights reserved. Terms of use.