Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 310225 - Last Review: December 3, 2007 - Revision: 4.2
How to use the Cdosys.dll library to save a message to a file by using Visual C#
This article was previously published under Q310225
Caution ADO and ADO MD have not been fully tested in a Microsoft .NET Framework environment. They may cause intermittent issues, especially in service-based applications or in multithreaded applications. The techniques that are discussed in this article should only be used as a temporary measure during migration to ADO.NET. You should only use these techniques after you have conducted complete testing to make sure that there are no compatibility issues. Any issues that are caused by using ADO or ADO MD in this manner are unsupported. For more information, see the following article in the Microsoft Knowledge Base:
840667 Â
(http://kbalertz.com/Feedback.aspx?kbNumber=840667/
)
You receive unexpected errors when using ADO and ADO MD in a .NET Framework application
This article describes how to use the Collaboration Data Objects (CDO) for Windows 2000 library (Cdosys.dll) to save a message to a file in Microsoft Visual C#.
Note The Cdosys.dll library is also known as CDOSYS.
To use CDOSYS as described in the "Summary" section, follow these steps:
- Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005.
- On the File menu, click New, and then click Project.
- Under Project Types, click Visual C# Projects, and then click Console Application under Templates. By default, Class1.cs is created.
Note In Microsoft Visual C# 2005, click Visual C# under Project Types. By default, Program.cs is created. - Add a reference to the Microsoft CDO For Windows 2000 Library. To do this, follow these steps:
- On the Project menu, click Add Reference.
- On the COM tab, locate Microsoft CDO For Windows 2000 Library, and then click Select.
Note In Microsoft Visual C# 2005, you do not have to click Select. - To accept your selections, click OK in the Add References dialog box.
If you receive a message to generate wrappers for the libraries that you selected, click Yes.
- In the code window, replace all the code with the following code:
namespace CdoSys
{
using System;
class Class1
{
static void Main(string[] args)
{
try
{
CDO.DropDirectory iDropDir = new CDO.DropDirectory();
CDO.IMessages iMsgs;
CDO.IMessage iMsg;
iMsgs = iDropDir.GetMessages("C:\\Inetpub\\mailroot\\Drop");
Console.WriteLine("Count: " + iMsgs.Count);
// Get first message.
iMsg = iMsgs[1];
ADODB.Stream stm = new ADODB.Stream();
stm.Open(System.Reflection.Missing.Value, ADODB.ConnectModeEnum.adModeUnknown,
ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified,
"", "");
stm.Type = ADODB.StreamTypeEnum.adTypeText;
stm.Charset = "US-ASCII";
CDO.IDataSource iDsrc;
iDsrc = iMsg.DataSource;
iDsrc.SaveToObject(stm, "_Stream");
// TODO: modify the file path.
stm.SaveToFile("C:\\temp\\Test.eml", ADODB.SaveOptionsEnum.adSaveCreateOverWrite);
iMsg = null;
iMsgs = null;
iDropDir = null;
iDsrc = null;
stm = null;
}
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
}
return;
}
}
} - Where TODO appears in the code, modify the code as indicated.
- To build and run the program, press F5.
For more information about
Microsoft Office Development with Visual Studio, see the following Microsoft Developer Network (MSDN) Web site:
For additional information about how to use CDOSYS, click the following article numbers to view the articles in the Microsoft Knowledge Base:
310212Â
(http://kbalertz.com/Feedback.aspx?kbNumber=310212/
)
How to use the Cdosys.dll library to send an e-mail with attachments
310221Â
(http://kbalertz.com/Feedback.aspx?kbNumber=310221/
)
How to use the Cdosys.dll library to embed a message in a new message by using Visual C# .NET
310224Â
(http://kbalertz.com/Feedback.aspx?kbNumber=310224/
)
How to use the Cdosys.dll library to process mail in the Drop directory by using Visual C# .NET
APPLIES TO
- Microsoft Visual C# 2005
- Microsoft Visual C# .NET 2003 Standard Edition
- Microsoft Visual C# .NET 2002 Standard Edition
- Microsoft Collaboration Data Objects 2.0
- Microsoft ActiveX Data Objects 2.5
- Microsoft ActiveX Data Objects 2.6
- Microsoft ActiveX Data Objects 2.7
- Microsoft Internet Information Services 6.0
- Microsoft Internet Information Services 5.0
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate
|
saqib mehmood
- saqibcode NOSPAM-AT-NOSPAM hotmail.com
|
Report As Irrelevant
|
| Written:
5/25/2005 10:49 PM |
|
|