1.启动 Microsoft Visual Studio.net,新建一个项目

2.添加COM 引用Microsoft ActiveX Data Object 2.5 Libary

3:示例

 

try
{
ADODB.Connection oCn
= new ADODB.Connection();
ADODB.Recordset oRs
= new ADODB.Recordset();

ADODB.Fields oFields;
ADODB.Field oField;

// TODO: Replace the folder URL with your folder URL.
string sFdUrl = "http://ExchServer/exchange/UserAlias/Inbox";

oCn.Provider
= "exoledb.datasource";
oCn.Open(sFdUrl,
"", "", -1);


string strSql;
strSql
= "";
strSql
= "select ";
strSql
= strSql + " \"urn:schemas:mailheader:content-class\"";
strSql
= strSql + ", \"DAV:href\" ";
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";
//TODO: Replace 'Test.eml' with the name of the mail that you want to delete.
strSql = strSql + " AND \"DAV:displayname\" = 'Test.eml'";


oRs.Open(strSql, oCn,
ADODB.CursorTypeEnum.adOpenUnspecified,
ADODB.LockTypeEnum.adLockOptimistic,
1);

Console.WriteLine(oRs.RecordCount);

oRs.MoveFirst();
while(!oRs.EOF)
{

oFields
= oRs.Fields;

oField
= oFields["DAV:href"];
Console.WriteLine(oField.Value);

oField
= oFields["DAV:displayname"];
Console.WriteLine(oField.Value);
oRs.Delete(ADODB.AffectEnum.adAffectCurrent);

oRs.MoveNext();
Console.WriteLine(
"Item Deleted");
Console.WriteLine(
"--------------------------");

}

oCn.Close();

oCn
= null;
oField
= null;
oFields
= null;
}
catch (Exception e)
{
Console.WriteLine(
"{0} Exception caught.", e);
}

 

 

 

相关文章:

  • 2021-11-05
  • 2021-11-02
  • 2022-12-23
  • 2021-07-10
  • 2021-12-25
  • 2021-08-23
猜你喜欢
  • 2021-12-16
  • 2022-01-17
  • 2021-08-09
  • 2021-11-27
  • 2021-10-29
  • 2021-05-19
  • 2021-09-24
相关资源
相似解决方案