473,503 Members | 1,711 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Exchange cdoex problem

Hi I'm trying to save a mail to a file but it doesn't create any and doesn't
come with errors, can anyone tell what is wrong with the saveto option ?

I can't seem to find anything on this.

using System;

using CDO;

namespace Samples

{

class Class1

{

static void Main(string[] args)

{

try

{

ADODB.Connection oCn = new ADODB.Connection();

ADODB.Recordset oRs = new ADODB.Recordset();

ADODB.Fields oFields;

ADODB.Field oField;

// TODO:

string sFdUrl = "http://crm/Exchange/administrator/Inbox";

oCn.Provider = "exoledb.datasource";

oCn.Open(sFdUrl, "", "", -1);

if (oCn.State == 1)

{

Console.WriteLine("Good Connection");

}

else

{

Console.WriteLine("Bad Connection");

}

string strSql;

strSql = "";

strSql = "select ";

strSql = strSql + " \"urn:schemas:mailheader:content-class\"";

strSql = strSql + ", \"DAV:href\" ";

strSql = strSql + ", \"urn:schemas:mailheader:content-class\" ";

strSql = strSql + ", \"DAV:displayname\"";

strSql = strSql + " from scope ('shallow traversal of " + "\"";

strSql = strSql + sFdUrl + "\"') ";

strSql = strSql + " WHERE \"DAV:ishidden\" = false";

strSql = strSql + " AND \"DAV:isfolder\" = false";

oRs.Open(strSql, oCn,

ADODB.CursorTypeEnum.adOpenUnspecified,

ADODB.LockTypeEnum.adLockOptimistic, 1);

// As an example, you only retrieve the first message.

// You can use a while loop through each message.

// Get the first message.

oRs.MoveFirst();

// Get Recordset fields.

oFields = oRs.Fields;

string sUrl;

oField = oFields["DAV:href"];

sUrl = oField.Value.ToString();

CDO.Message iMsg = new CDO.Message();

iMsg.DataSource.Open(sUrl, oRs.ActiveConnection,

ADODB.ConnectModeEnum.adModeReadWrite,

ADODB.RecordCreateOptionsEnum.adFailIfNotExists,

ADODB.RecordOpenOptionsEnum.adOpenSource,

"", "");

Console.WriteLine("{0}", iMsg.Sender);

Console.WriteLine("{0}", iMsg.Subject);

Console.WriteLine("{0}", iMsg.TextBody);

iMsg.DataSource.SaveTo(
@"c:\msg.eml",null,ADODB.ConnectModeEnum.adModeWri te,ADODB.RecordCreateOptionsEnum.adCreateOverwrite ,
ADODB.RecordOpenOptionsEnum.adOpenSource,"","");
// Get message fields.

oFields = iMsg.Fields;

for (int i = 0; i < oFields.Count; i++)

{

oField = oFields[i];

Console.WriteLine("{0} : {1}", oField.Name, oField.Value);

}

oRs.Close();

oCn.Close();

oCn = null;

oRs = null;

oFields = null;

oField = null;

}

catch (Exception e)

{

Console.WriteLine("{0} Exception caught.", e);

}

}

}

}

Sep 10 '07 #1
2 1438
Have you stepped through this code line by line in the debugger? You are
using COM Interop with this, both with CDO and with the classic ADO code,
lots of little things can go wrong. Try wrapping your code in a try / catch
block, catch and output any exception and write the Message and StackTrace
properties to the console.
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com

"Help needed" wrote:
Hi I'm trying to save a mail to a file but it doesn't create any and doesn't
come with errors, can anyone tell what is wrong with the saveto option ?

I can't seem to find anything on this.

using System;

using CDO;

namespace Samples

{

class Class1

{

static void Main(string[] args)

{

try

{

ADODB.Connection oCn = new ADODB.Connection();

ADODB.Recordset oRs = new ADODB.Recordset();

ADODB.Fields oFields;

ADODB.Field oField;

// TODO:

string sFdUrl = "http://crm/Exchange/administrator/Inbox";

oCn.Provider = "exoledb.datasource";

oCn.Open(sFdUrl, "", "", -1);

if (oCn.State == 1)

{

Console.WriteLine("Good Connection");

}

else

{

Console.WriteLine("Bad Connection");

}

string strSql;

strSql = "";

strSql = "select ";

strSql = strSql + " \"urn:schemas:mailheader:content-class\"";

strSql = strSql + ", \"DAV:href\" ";

strSql = strSql + ", \"urn:schemas:mailheader:content-class\" ";

strSql = strSql + ", \"DAV:displayname\"";

strSql = strSql + " from scope ('shallow traversal of " + "\"";

strSql = strSql + sFdUrl + "\"') ";

strSql = strSql + " WHERE \"DAV:ishidden\" = false";

strSql = strSql + " AND \"DAV:isfolder\" = false";

oRs.Open(strSql, oCn,

ADODB.CursorTypeEnum.adOpenUnspecified,

ADODB.LockTypeEnum.adLockOptimistic, 1);

// As an example, you only retrieve the first message.

// You can use a while loop through each message.

// Get the first message.

oRs.MoveFirst();

// Get Recordset fields.

oFields = oRs.Fields;

string sUrl;

oField = oFields["DAV:href"];

sUrl = oField.Value.ToString();

CDO.Message iMsg = new CDO.Message();

iMsg.DataSource.Open(sUrl, oRs.ActiveConnection,

ADODB.ConnectModeEnum.adModeReadWrite,

ADODB.RecordCreateOptionsEnum.adFailIfNotExists,

ADODB.RecordOpenOptionsEnum.adOpenSource,

"", "");

Console.WriteLine("{0}", iMsg.Sender);

Console.WriteLine("{0}", iMsg.Subject);

Console.WriteLine("{0}", iMsg.TextBody);

iMsg.DataSource.SaveTo(
@"c:\msg.eml",null,ADODB.ConnectModeEnum.adModeWri te,ADODB.RecordCreateOptionsEnum.adCreateOverwrite ,
ADODB.RecordOpenOptionsEnum.adOpenSource,"","");
// Get message fields.

oFields = iMsg.Fields;

for (int i = 0; i < oFields.Count; i++)

{

oField = oFields[i];

Console.WriteLine("{0} : {1}", oField.Name, oField.Value);

}

oRs.Close();

oCn.Close();

oCn = null;

oRs = null;

oFields = null;

oField = null;

}

catch (Exception e)

{

Console.WriteLine("{0} Exception caught.", e);

}

}

}

}

Sep 10 '07 #2
Also,
You can do DAV without having to resort to CDO and classic ADO - all with
managed code and no interop. Plenty of sample code out there if you care to
search for it.
Peter
--
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com

"Help needed" wrote:
Hi I'm trying to save a mail to a file but it doesn't create any and doesn't
come with errors, can anyone tell what is wrong with the saveto option ?

I can't seem to find anything on this.

using System;

using CDO;

namespace Samples

{

class Class1

{

static void Main(string[] args)

{

try

{

ADODB.Connection oCn = new ADODB.Connection();

ADODB.Recordset oRs = new ADODB.Recordset();

ADODB.Fields oFields;

ADODB.Field oField;

// TODO:

string sFdUrl = "http://crm/Exchange/administrator/Inbox";

oCn.Provider = "exoledb.datasource";

oCn.Open(sFdUrl, "", "", -1);

if (oCn.State == 1)

{

Console.WriteLine("Good Connection");

}

else

{

Console.WriteLine("Bad Connection");

}

string strSql;

strSql = "";

strSql = "select ";

strSql = strSql + " \"urn:schemas:mailheader:content-class\"";

strSql = strSql + ", \"DAV:href\" ";

strSql = strSql + ", \"urn:schemas:mailheader:content-class\" ";

strSql = strSql + ", \"DAV:displayname\"";

strSql = strSql + " from scope ('shallow traversal of " + "\"";

strSql = strSql + sFdUrl + "\"') ";

strSql = strSql + " WHERE \"DAV:ishidden\" = false";

strSql = strSql + " AND \"DAV:isfolder\" = false";

oRs.Open(strSql, oCn,

ADODB.CursorTypeEnum.adOpenUnspecified,

ADODB.LockTypeEnum.adLockOptimistic, 1);

// As an example, you only retrieve the first message.

// You can use a while loop through each message.

// Get the first message.

oRs.MoveFirst();

// Get Recordset fields.

oFields = oRs.Fields;

string sUrl;

oField = oFields["DAV:href"];

sUrl = oField.Value.ToString();

CDO.Message iMsg = new CDO.Message();

iMsg.DataSource.Open(sUrl, oRs.ActiveConnection,

ADODB.ConnectModeEnum.adModeReadWrite,

ADODB.RecordCreateOptionsEnum.adFailIfNotExists,

ADODB.RecordOpenOptionsEnum.adOpenSource,

"", "");

Console.WriteLine("{0}", iMsg.Sender);

Console.WriteLine("{0}", iMsg.Subject);

Console.WriteLine("{0}", iMsg.TextBody);

iMsg.DataSource.SaveTo(
@"c:\msg.eml",null,ADODB.ConnectModeEnum.adModeWri te,ADODB.RecordCreateOptionsEnum.adCreateOverwrite ,
ADODB.RecordOpenOptionsEnum.adOpenSource,"","");
// Get message fields.

oFields = iMsg.Fields;

for (int i = 0; i < oFields.Count; i++)

{

oField = oFields[i];

Console.WriteLine("{0} : {1}", oField.Name, oField.Value);

}

oRs.Close();

oCn.Close();

oCn = null;

oRs = null;

oFields = null;

oField = null;

}

catch (Exception e)

{

Console.WriteLine("{0} Exception caught.", e);

}

}

}

}

Sep 10 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
953
by: dave | last post by:
I am looking for code resources on how to read ms exchange calendar with vb.net. Can anyone point me in the right direction to some code samples thx
4
3391
by: gerry | last post by:
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 (...
2
11054
by: Gaz | last post by:
Hi all I am currently trying to send and email via exchange except I'm having a nightmare getting it working, you'd think this would be pertty simple wouldn't you? I have added a reference to...
8
3395
by: Rob Edwards | last post by:
When trying to add the Microsoft CDO for Exchange Management Library (aka CDOEXM.dll) I receive the following message: "A reference to 'Microsoft CDO for Exchange Management Library' could not be...
0
1644
by: Diego F. | last post by:
Hi. I need to add appointments in Exchange Server 2003 calendar from a ASP.NET application. I've been searching and in the MSDN there are two articles with samples of doing it with CDOEX and...
3
24652
by: Christoph M?der | last post by:
Hello, i am writting an programm which should connect to an exchange server and get calendar entries. i have tried it with ADODB, but there was a problem: sometimes it works, sometimes not. ...
4
4018
by: Sean Feldman | last post by:
Hi, I'm searching for a way to connect to exchange e-mail box in order to extract attached files. Please advise where I can get more reading about this, thank you. Sh.
2
2952
by: LVP | last post by:
Hi Everyone, I am looking to get emails from a Public Folder on our internal server using a filter from exchange server 2007 extract attachments tag or set the status on each email so I don't...
2
962
by: chelluchittibabu | last post by:
hi, any one knows, how to synchronize a exchange server with other servers in .net? i am using cdoex dll for communication with exchange server. pls let me know if any one knows. regards,...
0
7086
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7330
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.