Exchange cdoex problem

H

Help needed

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.adModeWrite,ADODB.RecordCreateOptionsEnum.adCreateOverwrite,
ADODB.RecordOpenOptionsEnum.adOpenSource,"","");


// Get message fields.

oFields = iMsg.Fields;



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

{

oField = oFields;

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);

}

}

}

}
 
G

Guest

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 said:
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.adModeWrite,ADODB.RecordCreateOptionsEnum.adCreateOverwrite,
ADODB.RecordOpenOptionsEnum.adOpenSource,"","");


// Get message fields.

oFields = iMsg.Fields;



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

{

oField = oFields;

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);

}

}

}

}
 
G

Guest

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 said:
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.adModeWrite,ADODB.RecordCreateOptionsEnum.adCreateOverwrite,
ADODB.RecordOpenOptionsEnum.adOpenSource,"","");


// Get message fields.

oFields = iMsg.Fields;



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

{

oField = oFields;

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);

}

}

}

}
 

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