SaveToFile within Exchange Store Event

G

gerry

I have an async OnStore event written in c# and registered in exchange 2003.
Everything seems to be working fine other than the SaveToFile().
If there is an error in the iMessage.DataSource.Open ( ie. the message has
moved ) the expected exception is raised and caught.
However when the strm.SaveToFile() is executed the process just seems to
die - no output file is generated , no exceptions raised , no system log
entries , no more log() entries are written - nothing.
If I comment this line out , the method runs to completion as it should.

The log() method writes to a log in the same target directory as the
SaveToFile so this is not a permissions problem on the destination file.

any insights here would be appreciated

gerry



void IExStoreAsyncEvents.OnSave( IExStoreEventInfo info , string url , int
flags )
{
pid=System.DateTime.Now.Ticks;
IExStoreDispEventInfo dinfo = (IExStoreDispEventInfo)info;
log("OnSave",String.Format("url:{0}\n\tflags:0x{1:x4}\n\tsource URL :
{2}",url,flags,dinfo.SourceURL));

// if ( ( flags & 0x08 ) != 0x00 ) return;

// sleep here to let system filters/rules etc take effect
// if message is moved elsewhere - Open will fail
log("OnSave","Sleep(1)");
System.Threading.Thread.Sleep(4000);
log("OnSave","1");

try
{
log("OnSave","iMessage=new CDO.Message()");
CDO.Message iMessage=new CDO.MessageClass();
log("OnSave","iMessage.DataSource.Open");
iMessage.DataSource.Open(url,null,
ADODB.ConnectModeEnum.adModeRead,
ADODB.RecordCreateOptionsEnum.adFailIfNotExists,
ADODB.RecordOpenOptionsEnum.adOpenSource,"","");
try
{
String dstFile=String.Format("{0}\\m{1}.eml",appRoot,pid);
log("OnSave",dstFile);
log("OnSave","strm = iMessage.GetStream()");
ADODB.Stream strm = iMessage.GetStream();
log("OnSave","strm.SaveToFile");

strm.SaveToFile(dstFile,ADODB.SaveOptionsEnum.adSaveCreateOverWrite);
log("OnSave","saved");
strm.Close();
}
catch (Exception e)
{
log("Exc1",e.ToString());
}
}
catch (Exception e)
{
log("Exc2",e.ToString());
}
log("OnSave","Done");
}
 
Y

Yan-Hong Huang[MSFT]

Hello Gerry,

Based on my understanding, the problem is: You are writing contents of one
message to a disk file in IExStoreAsyncEvents.OnSave function. However,
this stream.SaveToFile function doesn't write anything. Right?

Generally speaking, to save a serialized message from a Message object into
a Microsoft? ActiveX? Data Objects (ADO) Stream object, perform the
following steps:

1) Retrieve the IDataSource interface on the Message object.
2) Create or otherwise obtain a _Stream object reference on an ADO Stream
object.
3) Using the IDataSource interface on the Message object, call the
SaveToObject method, passing the _Stream object reference as the first
argument, and the string "_Stream" as the second

The sample VB code likes:
' Reference to Microsoft ActiveX Data Objects 2.5 Library
' Reference to Microsoft CDO for Windows 2000 Library
Sub SaveMessageToFile(iMsg As CDO.Message, Filepath As String)
Dim Stm As New Stream
Stm.Open
Stm.Type = adTypeText
Stm.Charset = "US-ASCII"

Dim iDsrc As IDataSource
Set iDsrc = iMsg
iDsrc.SaveToObject Stm, "_Stream"

Stm.SaveToFile Filepath, adSaveCreateOverWrite

End Sub

For details, please refer to "Saving Messages into ADO Stream Objects"
topic in MSDN. Please search the topic and select "search in titles only"
to get that.

Also, you can refer to
http://msdn.microsoft.com/library/en-us/cdosys/html/_cdosys_idatasource_inte
rface.asp?frame=true for some demo code.

In Internet, we can also find a sample at
http://www.codeproject.com/csharp/CsManagedEventSinksHooks.asp. However, it
is somewhat different since the author uses FileStream to save some content
to a file.

Please test the above and let me know whether it works. If there is any
questions, please feel free to let me know.

Thanks very much.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

gerry

Hi ,
thanks for the reply.

I did get this all staightened out - it turned out to be a simple fix
completely unrelated to my code which now works as stated without
modification.

since an exchange async store event handler has to be a com+ package, all
referenced .NET dlls have to be strongly named.
so i manually created & signed interop dll's for adodb.dll , exoledb.dll and
cdoex.dll.
what i didn't notice was that the required interop dll for adodb.dll is
already included with the .net installation.
using the distributed adodb interop dll instead of the one I created solved
the problem.
obviously ms has done some 'magic' in the generation of the adodb interop
dll to resolve some problem with standard interop dll generation.

gerry
 
Y

Yan-Hong Huang[MSFT]

Hello Gerry,

Sorry that my suggestion didn't help you resolve the problem. However, I am
glad to know that you have figured it out by yourself. Thanks very much
for sharing your experience in the community and I believe it could benefit
other developers much.

Thanks again for participating the community.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Y

Yan-Hong Huang[MSFT]

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top