操作exchange类库代码

最佳的Exchange .NET开发 Exchange API 下表汇总在.net 环境中 Exchange api 支持策略: 收起该表格展开该表格APIDLL 名称托管代码支持策略System.Web.Mails支持WebDAV支持WMI支持CDOSYSCDOSYS.DLL支持,但是 System.Web.Mail 建议CDOEXMCDOEXM.DLL通过使用 COM 互操作程序集支持EXOLEDB通过使用 COM 互操作程序集支持CDOEXCDOEX.DLL支持通过使用一个 COM 互操作程序集CDO 1.2 xCDO.DLL不支持CDONTSCDONTS.DLL 阅读详情

操作exchange类库代码

为日历中的约会定义的实体
using System;
using System.Collections;

namespace ISoftStone.AccessExchange.WebDav
{
    
/// <summary>
    
/// CalendarItemInfo 的摘要说明。
    
/// </summary>

    public class CalendarItemInfo
    
{
        
private string mName;
        
public string Name
        
{
            
get
            
{
                
return this.mName;
            }

            
set
            
{
                
this.mName = value;
            }

        }

        
private string mLocation;
        
private DateTime mBeginTime ;
        
private DateTime mEndTime;
        
private int mInstanceType = 0;
        
private string mBusyStatus = "BUSY";
        
private string mMeetingStatus = "CONFIRMED";
        
private bool mIsAllDayEvent = false;
        
public bool IsAllDayEvent
        
{
            
get
            
{
                
return this.mIsAllDayEvent;
            }

            
set
            
{
                
this.mIsAllDayEvent = value;
            }

        }

        
private bool mResponseRequested = true;
        
public bool ResponseRequested
        
{
            
get
            
{
                
return this.mResponseRequested;
            }

            
set
            
{
                
this.mResponseRequested = value;
            }

        }

        
private  int mReminderOffset = 900; //seconds
        public int ReminderOffset
        
{
            
get
            
{
                
return this.mReminderOffset;
            }

            
set
            
{
                
this.mReminderOffset = value;
            }

        }

        
private string  mMailToListMust;
        
public string MailToListMust
        
{
            
get
            
{
                
return this.mMailToListMust;
            }

            
set
            
{
                
this.mMailToListMust = value;
            }

        }

        
private string mMailToList;
        
public string MailToList
        
{
            
get
            
{
                
return this.mMailToList;
            }

            
set
            
{
                
this.mMailToList = value;
            }

        }


        
private string mSubject;
        
public string Subject
        
{
            
get
            
{
                
return this.mSubject;
            }

            
set
            
{
                
this.mSubject = value;
            }

        }

        
private string mHtmlDescription;
        
public string HtmlDescription
        
{
            
get
            
{
                
return this.mHtmlDescription;
            }

            
set
            
{
                
this.mHtmlDescription = value;
            }

        }

        
private bool mIsFinvited = true;
        
public bool IsFinvited
        
{
            
get
            
{
                
return this.mIsFinvited;
            }

            
set
            
{
                
this.mIsFinvited = value;
            }

        }

        
/// <summary>
        
/// 所在位置
        
/// </summary>

        public string Location
        
{
            
get
            
{
                
return this.mLocation;
            }

            
set
            
{
                
this.mLocation = value;
            }

        }

        
/// <summary>
        
/// 约会开始时间
        
/// </summary>

        public DateTime BeginTime
        
{
            
get
            
{
                
return mBeginTime;
            }

            
set
            
{
                mBeginTime 
= value;
            }

        }

        
/// <summary>
        
/// 约会结束时间
        
/// </summary>

        public DateTime EndTime
        
{
            
get
            
{
                
return this.mEndTime;
            }

            
set
            
{
                
this.mEndTime = value;
            }

        }

        
public int InstanceType
        
{
            
get
            
{
                
return this.mInstanceType;
            }

            
set
            
{
                
this.mInstanceType = value;
            }

        }

        
public string BusyStatus
        
{
            
get
            
{
                
return this.mBusyStatus;
            }

            
set
            
{
                
this.mBusyStatus = value;
            }

        }

        
public string MeetingStatus
        
{
            
get
            
{
                
return this.mMeetingStatus;

            }

            
set
            
{
                
this.mMeetingStatus = value;
            }

        }


        
public int GetBoolInt(bool any)
        
{
            
if (any)
            
{
                
return 1;
            }

            
return 0;
        }

        

        
public CalendarItemInfo()
        
{
            
//
            
// TODO: 在此处添加构造函数逻辑
            
//
        }

    }

}



User

using System;

namespace ISoftStone.AccessExchange.WebDav
{
    
/// <summary>
    
/// User 的摘要说明。
    
/// </summary>

    public class User
    
{
        
private string m_Name;
        
private string m_Password;
        
private string m_Domain;

        
public string Name
        
{
            
get
            
{
                
return m_Name;
            }

            
set
            
{
                m_Name 
= value;
            }

        }

        
public string Password
        
{
            
get
            
{
                
return m_Password;
            }

            
set
            
{
                m_Password 
= value;
            }

        }


        
public string Domain
        
{
            
get
            
{
                
return m_Domain;
            }

            
set
            
{
                m_Domain 
= value;
            }

        }

        
private User(string name,string password,string domain)
        
{
            m_Name 
= name;
            m_Password 
= password;
            m_Domain 
= domain;
        }

        
public static User GetUser(string name,string password,string domain)
        
{
            
return  new User(name,password,domain);
            
        }

        
public static User GetUser(string name,string password)
        
{
            
return new User(name,password,String.Empty);
        }

    }

}


session
using System;
using System.Net;

namespace ISoftStone.AccessExchange.WebDav
{
    
/// <summary>
    
///This class is for the session management of WebExchange class. 
    
/// </summary>

    public class WebDavSession
    
{
        
#region Fields 

        
private string m_UserMailUrl;
        
private ICredentials m_Credentials;
        
private WebProxy m_Proxy;

        
#endregion

        
#region Property

        
/// <summary>
        
/// user's mailbox url
        
/// </summary>

        public string UserMailUrl
        
{
            
get
            
{
                
return m_UserMailUrl;
            }

            
set
            
{
                m_UserMailUrl 
= value;
            }

        }

        
/// <summary>
        
/// web proxy 
        
/// </summary>

        public WebProxy Proxy
        
{
            
get
            
{
                
return m_Proxy;
            }

            
set
            
{
                m_Proxy 
= value;
            }

        }

        
public ICredentials Credentials 
        
{
            
get
            
{
                
return m_Credentials;
            }

            
set
            
{
                m_Credentials 
= value;
            }

        }

        
#endregion


        
public static WebDavSession GetSession(ICredentials obj)
        
{
            WebDavSession session 
=  new WebDavSession();
            session.Credentials 
= obj;
            
return session;
        }

        
public static WebDavSession GetSession(User user)
        
{
            
return GetSession(user,String.Empty);
        }

        
public static WebDavSession GetSession(User user,WebProxy proxy)
        
{
            
return GetSession(user,String.Empty,proxy);
        }


        
public static WebDavSession GetSession(User user,string userMailUrl)
        
{
            
return GetSession(user,userMailUrl,null);
        }

        
public static WebDavSession GetSession(User user,string userMailUrl,WebProxy proxy)
        
{
            WebDavSession session 
= new WebDavSession();
            session.UserMailUrl 
= userMailUrl;
            session.Proxy 
= proxy;
            
if(user.Domain.Equals(String.Empty))
            
{
                CredentialCache myCredentialCache 
= new CredentialCache();
                myCredentialCache.Add( 
new System.Uri(userMailUrl),"NTLM",
                    
new NetworkCredential(user.Name,user.Password));
                session.Credentials 
= myCredentialCache;
            }

            
else
            
{
                CredentialCache myCredentialCache 
= new CredentialCache();
                myCredentialCache.Add( 
new System.Uri(userMailUrl),"NTLM",
                    
new NetworkCredential(user.Name,user.Password,user.Domain));
                session.Credentials 
= myCredentialCache;
            }

            
return session;
        }

        
public WebDavSession()
        
{
            
//
            
// TODO: 在此处添加构造函数逻辑
            
//
        }

    }

}



using System;
using System.Net;
using System.Text;
using System.Xml;
using System.IO;
using System.Data;

namespace ISoftStone.AccessExchange.WebDav
{
    
/// <summary>
    
/// WebExchange 的摘要说明。
    
/// </summary>

    public class WebExchange
    
{
        
private WebDavSession m_Session;
        
private string m_Url;
        
private Encoding m_Encode;

        
private HttpWebRequest objRequest;
        
private WebResponse objResponse;

        
        

        
public WebDavSession Session
        
{
            
get
            
{
                
if(m_Session == null)
                
{
                    m_Session 
= new WebDavSession();
                }

                
return m_Session;
            }

            
set
            
{
                m_Session 
= value;
            }

        }

        
public string Url
        
{
            
get
            
{
                
if(m_Url != null)
                
{
                    
if(m_Url.LastIndexOf("/") == m_Url.Length -1)
                    
{
                        
return m_Url.Substring(0,m_Url.Length-1);
                    }

                }

                
return m_Url;
            }

            
set
            
{
                m_Url 
= value;
            }

        }

        
public Encoding Encode
        
{
            
get
            
{
                
if (m_Encode == null)
                
{
                    m_Encode 
= new UTF8Encoding();
                }

                
return m_Encode;
            }

            
set
            
{
                m_Encode 
= value;
            }

        }

        
        
public WebExchange(WebDavSession webDavSession)
        
{
            m_Session 
= webDavSession;
            m_Url 
= webDavSession.UserMailUrl;
        }

        
public WebExchange(WebDavSession webDavSession,string url)
        
{
            m_Session 
= webDavSession;
            m_Url 
= url;
        }

        
public WebExchange(string url)
        
{
            m_Url 
= url;
        }

        
public void CreateCalendarItem(CalendarItemInfo itemInfo)
        
{
            

            
byte[] bytes = null;
            Stream requestStream 
= null;
            Stream responseStream 
= null;
            
string strMailbox = "jianli";
            
string strXMLNSInfo =null;
            
try
            
{
                objRequest 
= (System.Net.HttpWebRequest)HttpWebRequest.Create(this.Url + "/" + itemInfo.Name);
                
//objRequest = (HttpWebRequest)HttpWebRequest.Create(this.Url + "/" + "testdee");
                
// Add the network credentials to the request.
                objRequest.Credentials = Session.Credentials;
                
// Specify the DELETE method.
                objRequest.Method = "PROPPATCH";
                
// XML namespace info for the WebDAV request.
                strXMLNSInfo = "xmlns:g=/"DAV:/" "
                    
+ "xmlns:e=/"http://schemas.microsoft.com/exchange//" "
                    + "xmlns:mapi=/"http://schemas.microsoft.com/mapi//" "
                    + "xmlns:mapit=/"http://schemas.microsoft.com/mapi/proptag//" "
                    + "xmlns:x=/"xml:/" xmlns:cal=/"urn:schemas:calendar:/" "
                    
+ "xmlns:dt=/"urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882//" "
                    
+ "xmlns:header=/"urn:schemas:mailheader:/" "
                    
+ "xmlns:mail=/"urn:schemas:httpmail:/"";

                
// Set the appointment item properties.  To create an all-day meeting,
                
// set the dtstart/dtend range for 24 hours or more and set the alldayevent property
                
// to 1.  See the documentation on the properties
                
// in the urn:schemas:calendar: namespace for more information.
                string strCalInfo = "<cal:location>" + itemInfo.Location + "</cal:location>"
                    
+ "<cal:dtstart dt:dt=/"dateTime.tz/">2005-04-24T08:00:00.000Z</cal:dtstart>"
                
                    
+ "<cal:dtend dt:dt=/"dateTime.tz/">2005-04-24T08:40:00.000Z</cal:dtend>"
//                    + "<cal:dtstart dt:dt=/"dateTime.tz/">" + itemInfo.BeginTime.ToShortDateString() + "T" + itemInfo.BeginTime.ToLongTimeString() + ".000Z" + "</cal:dtstart>"
//                    + "<cal:dtend dt:dt=/"dateTime.tz/">"  + itemInfo.EndTime.ToShortDateString() + "T" + itemInfo.EndTime.ToLongTimeString() + ".000Z" +  "</cal:dtend>"
                    + "<cal:instancetype dt:dt=/"int/">" + itemInfo.InstanceType.ToString() + "</cal:instancetype>"
                    

                    

                    
+ "<cal:busystatus>" + itemInfo.BusyStatus + "</cal:busystatus>"
                    
+ "<cal:meetingstatus> " + itemInfo.MeetingStatus.ToString() + "</cal:meetingstatus>"
                    
+ "<cal:alldayevent dt:dt=/"boolean/">" + itemInfo.GetBoolInt(itemInfo.IsAllDayEvent).ToString() + "</cal:alldayevent>"
                    
+ "<cal:responserequested dt:dt=/"boolean/">" + itemInfo.GetBoolInt(itemInfo.IsAllDayEvent).ToString() + "</cal:responserequested>"
                    
// Set the reminder time (in seconds).
                    + "<cal:reminderoffset dt:dt=/"int/">" + itemInfo.ReminderOffset.ToString() +"</cal:reminderoffset>";

//                string strCalInfo = "<cal:location>meetappt Location</cal:location>"
//                    + "<cal:dtstart dt:dt=/"dateTime.tz/">2004-05-18T23:00:00.000Z</cal:dtstart>"
//                    + "<cal:dtend dt:dt=/"dateTime.tz/">2004-05-18T23:30:00.000Z</cal:dtend>"
//                    + "<cal:instancetype dt:dt=/"int/">0</cal:instancetype>"
//                    + "<cal:busystatus>BUSY</cal:busystatus>"
//                    + "<cal:meetingstatus>CONFIRMED</cal:meetingstatus>"
//                    + "<cal:alldayevent dt:dt=/"boolean/">0</cal:alldayevent>"
//                    + "<cal:responserequested dt:dt=/"boolean/">1</cal:responserequested>"
//
//                    // Set the reminder time (in seconds).
//                    + "<cal:reminderoffset dt:dt=/"int/">900</cal:reminderoffset>";
//
//


                
// Set the required attendee of the appointment.
                string strHeaderInfo = "<header:to>" + itemInfo.MailToListMust + "</header:to>";

                
// Set the subject of the appointment.
                string strMailInfo = "<mail:subject>" + itemInfo.Subject + "</mail:subject>"
                    
+ "<mail:htmldescription>" + itemInfo.HtmlDescription + "</mail:htmldescription>";

                
// Build the XML body of the PROPPATCH request.
                string strApptRequest = "<?xml version=/"1.0/"?>"
                    
+ "<g:propertyupdate " + strXMLNSInfo + ">"
                    
+ "<g:set><g:prop>"
                    
+ "<g:contentclass>urn:content-classes:appointment</g:contentclass>"
                    
+ "<e:outlookmessageclass>IPM.Appointment</e:outlookmessageclass>"
                    
+ strMailInfo
                    
+ strCalInfo
                    
+ strHeaderInfo
                    
+ "<mapi:finvited dt:dt=/"boolean/">1</mapi:finvited>"
                    
+ "</g:prop></g:set>"
                    
+ "</g:propertyupdate>";


                bytes 
= this.Encode.GetBytes((string)strApptRequest);
                
                
// Set the content header length.  This must be
                
// done before writing data to the request stream.
                objRequest.ContentLength = bytes.Length;

                
// Get a reference to the request stream.
                requestStream = objRequest.GetRequestStream();

                
                
// Write the request body to the request stream.
                requestStream.Write(bytes, 0, bytes.Length);

                
// Close the Stream object to release the connection
                
// for further use.
                requestStream.Close();

                
// Set the content type header.
                objRequest.ContentType = "text/xml";

                
// Send the PROPFIND method request and get the
                
// response from the server.
                objResponse = (HttpWebResponse)objRequest.GetResponse();
                
//return null;

                
// Get the XML response stream.
                responseStream = objResponse.GetResponseStream();
                
// Close the HttpWebResponse object.
                objResponse.Close();
                responseStream.Close();
                
//Console.WriteLine("Item successfully deleted.")
            }

            
catch(Exception ex)
            
{
                
// Catch any exceptions. Any error codes from the PROPPATCH
                
// method request on the server will be caught
                
// here, also.
                throw new Exception("can't create item " + ex.ToString());
            }


        }

        
public void CreateCalendarItem(string itemName)
        
{
            
byte[] bytes = null;
            Stream requestStream 
= null;
            Stream responseStream 
= null;
            
string strMailbox = "jianli";
            
try
            
{
                objRequest 
= (System.Net.HttpWebRequest)HttpWebRequest.Create(this.Url + "/" + itemName);

                
// Add the network credentials to the request.
                objRequest.Credentials = this.Session.Credentials;

                
// Specify the DELETE method.
                objRequest.Method = "PROPPATCH";

                
// XML namespace info for the WebDAV request.
                string strXMLNSInfo = "xmlns:g=/"DAV:/" "
                    
+ "xmlns:e=/"http://schemas.microsoft.com/exchange//" "
                    + "xmlns:mapi=/"http://schemas.microsoft.com/mapi//" "
                    + "xmlns:mapit=/"http://schemas.microsoft.com/mapi/proptag//" "
                    + "xmlns:x=/"xml:/" xmlns:cal=/"urn:schemas:calendar:/" "
                    
+ "xmlns:dt=/"urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882//" "
                    
+ "xmlns:header=/"urn:schemas:mailheader:/" "
                    
+ "xmlns:mail=/"urn:schemas:httpmail:/"";

                
// Set the appointment item properties.  To create an all-day meeting,
                
// set the dtstart/dtend range for 24 hours or more and set the alldayevent property
                
// to 1.  See the documentation on the properties
                
// in the urn:schemas:calendar: namespace for more information.
                string strCalInfo = "<cal:location>meetappt Location</cal:location>"
                    
+ "<cal:dtstart dt:dt=/"dateTime.tz/">2004-05-18T23:00:00.000Z</cal:dtstart>"
                    
+ "<cal:dtend dt:dt=/"dateTime.tz/">2004-05-18T23:30:00.000Z</cal:dtend>"
                    
+ "<cal:instancetype dt:dt=/"int/">0</cal:instancetype>"
                    
+ "<cal:busystatus>BUSY</cal:busystatus>"
                    
+ "<cal:meetingstatus>CONFIRMED</cal:meetingstatus>"
                    
+ "<cal:alldayevent dt:dt=/"boolean/">0</cal:alldayevent>"
                    
+ "<cal:responserequested dt:dt=/"boolean/">1</cal:responserequested>"

                    
// Set the reminder time (in seconds).
                    + "<cal:reminderoffset dt:dt=/"int/">900</cal:reminderoffset>";

                
// Set the required attendee of the appointment.
                string strHeaderInfo = "<header:to>" + strMailbox + ";章清平 &lt;qpzhang@iisdnet.com &gt;></header:to>";

                
// Set the subject of the appointment.
                string strMailInfo = "<mail:subject>Test Appointment Subject</mail:subject>"
                    
+ "<mail:htmldescription>Let's meet here</mail:htmldescription>";

                
// Build the XML body of the PROPPATCH request.
                string strApptRequest = "<?xml version=/"1.0/"?>"
                    
+ "<g:propertyupdate " + strXMLNSInfo + ">"
                    
+ "<g:set><g:prop>"
                    
+ "<g:contentclass>urn:content-classes:appointment</g:contentclass>"
                    
+ "<e:outlookmessageclass>IPM.Appointment</e:outlookmessageclass>"
                    
+ strMailInfo
                    
+ strCalInfo
                    
+ strHeaderInfo
                    
+ "<mapi:finvited dt:dt=/"boolean/">1</mapi:finvited>"
                    
+ "</g:prop></g:set>"
                    
+ "</g:propertyupdate>";


                bytes 
= this.Encode.GetBytes((string)strApptRequest);
                
                
// Set the content header length.  This must be
                
// done before writing data to the request stream.
                objRequest.ContentLength = bytes.Length;

                
// Get a reference to the request stream.
                requestStream = objRequest.GetRequestStream();

                
                
// Write the request body to the request stream.
                requestStream.Write(bytes, 0, bytes.Length);

                
// Close the Stream object to release the connection
                
// for further use.
                requestStream.Close();

                
// Set the content type header.
                objRequest.ContentType = "text/xml";

                
                
// Send the PROPFIND method request and get the
                
// response from the server.
                objResponse = (HttpWebResponse)objRequest.GetResponse();
                
//return null;

                
// Get the XML response stream.
                responseStream = objResponse.GetResponseStream();

                
// Close the HttpWebResponse object.
                objResponse.Close();
                responseStream.Close();
                

                
//Console.WriteLine("Item successfully deleted.")

            }

            
catch(Exception ex)
            
{
                
// Catch any exceptions. Any error codes from the PROPPATCH
                
// method request on the server will be caught
                
// here, also.
                throw new Exception("can't create item " + ex.ToString());
            }


        }

        
public void GetInfo()
        
{
//            string strXml;
//            strXml = "<?xml version='"+"1.0"+"'?>";
//            strXml = strXml + "<a:propfind xmlns:a='"+"DAV:"+"'  xmlns:e='"+"urn:schemas:httpmail:'"+">";
//            strXml = strXml + "<a:prop>";
//            //日历
//            strXml = strXml + "<e:calendar/>";
//            
//            //联系人
//            strXml = strXml + "<e:contacts/>";
//            
//            //回收站
//            strXml = strXml + "<e:deleteditems/>";
//            
//            //草稿
//            strXml = strXml + "<e:drafts/>";
//            
//            //收件箱
//            strXml = strXml + "<e:inbox/>";
//            
//            //日记
//            strXml = strXml + "<e:journal/>";
//            
//            //便笺
//            strXml = strXml + "<e:notes/>";
//            
//            //发件箱
//            strXml = strXml + "<e:outbox/>";
//            
//            //已发邮件
//            strXml = strXml + "<e:sentitems/>";
//            
//            //任务
//            strXml = strXml + "<e:tasks/>";
//            
//            //短信
//            strXml = strXml + "<e:sendmsg/>";
//            strXml = strXml + "<e:msgfolderroot/>";
//            strXml = strXml + "</a:prop>";
//            strXml = strXml + "</a:propfind>";
//
//            //声明XMLHTTP对象
//            MSXML2.XMLHTTP30Class objXmlHttp=new MSXML2.XMLHTTP30Class();
//            //声明DOMDocument对象
//            MSXML2.DOMDocument30Class  objXmlDOMDocument=new MSXML2.DOMDocument30Class();
//            objXmlHttp.open("PROPFIND",strUserFolder,false,strDomainName+"//"+strUserName,strUserPwd);
//            objXmlHttp.setRequestHeader("content-type","text/xml");
//            objXmlHttp.setRequestHeader("depth","0");
//            objXmlHttp.send(strXml);
//    
//            if (objXmlHttp.status.ToString()=="207") //DAV读取正确
//            {
//                objXmlDOMDocument.load(objXmlHttp.responseXML);
//                
//                //日历
//                strCalendar=objXmlDOMDocument.selectSingleNode("//a:multistatus/a:response/a:propstat/a:prop/d:calendar").text;
//                
//                //联系人
//                strContacts=objXmlDOMDocument.selectSingleNode("//a:multistatus/a:response/a:propstat/a:prop/d:contacts").text;
//                
//                //垃圾箱
//                strDeleteditems=objXmlDOMDocument.selectSingleNode("//a:multistatus/a:response/a:propstat/a:prop/d:deleteditems").text;
//                
//                //草稿
//                strDrafts=objXmlDOMDocument.selectSingleNode("//a:multistatus/a:response/a:propstat/a:prop/d:drafts").text;
//                
//                //收件箱
//                strInbox=objXmlDOMDocument.selectSingleNode("//a:multistatus/a:response/a:propstat/a:prop/d:inbox").text;
//                
//                //日记
//                strJournal=objXmlDOMDocument.selectSingleNode("//a:multistatus/a:response/a:propstat/a:prop/d:journal").text;
//                
//                //便笺
//                strNotes=objXmlDOMDocument.selectSingleNode("//a:multistatus/a:response/a:propstat/a:prop/d:notes").text;
//                
//                //发件箱
//                strOutbox=objXmlDOMDocument.selectSingleNode("//a:multistatus/a:response/a:propstat/a:prop/d:outbox").text;
//                
//                //已发邮件
//                strSentitems=objXmlDOMDocument.selectSingleNode("//a:multistatus/a:response/a:propstat/a:prop/d:sentitems").text;
//                
//                //任务
//                strTasks=objXmlDOMDocument.selectSingleNode("//a:multistatus/a:response/a:propstat/a:prop/d:tasks").text;
//                        
//                //短信
//                strSendmsg=objXmlDOMDocument.selectSingleNode("//a:multistatus/a:response/a:propstat/a:prop/d:sendmsg").text;
//                
//                strMsgfolderroot=objXmlDOMDocument.selectSingleNode("//a:multistatus/a:response/a:propstat/a:prop/d:msgfolderroot").text;
//                
//                //Label1.Text=strCalendar+strDeleteditems;//debug
//            }
//            else //DAV读取错误
//            {
//                Response.Write("<?xml version='1.0' encoding='GB2312'?>");
//                Response.Write("<Error>");
//                Response.Write("<Status>" + objXmlHttp.status + "</Status>");
//                Response.Write("<Statustext>" + objXmlHttp.statusText.ToString() + "</Statustext>");
//                Response.Write("</Error>");
//            }
//        



        }

        
public XmlDocument SearchItems(string xmlSearchBody)
        
{
            
//string strSrcURI = ItemURL;

            
byte[] bytes = null;
            Stream requestStream 
= null;
            Stream responseStream 
= null;
            XmlDocument responseXmlDoc 
= null;

            
try
            
{
                
                
// Create the HttpWebRequest object.
                objRequest = (HttpWebRequest)HttpWebRequest.Create(Url);
                
// Add the network credentials to the request.
                objRequest.Credentials = m_Session.Credentials;
                
// Specify the method.
                
//objRequest.Method = "PROPFIND";
                objRequest.Method = "SEARCH";
                
// Encode the body 
                bytes = this.Encode.GetBytes((string)xmlSearchBody);
                
                
// Set the content header length.  This must be
                
// done before writing data to the request stream.
                objRequest.ContentLength = bytes.Length;

                
// Get a reference to the request stream.
                requestStream = objRequest.GetRequestStream();
                

                
// Write the request body to the request stream.
                requestStream.Write(bytes, 0, bytes.Length);

                
// Close the Stream object to release the connection
                
// for further use.
                requestStream.Close();

                
// Set the content type header.
                objRequest.ContentType = "text/xml";

                
// Send the PROPFIND method request and get the
                
// response from the server.
                objResponse = (HttpWebResponse)objRequest.GetResponse();
                
//return null;

                
// Get the XML response stream.
                responseStream = objResponse.GetResponseStream();

                
// Create the XmlDocument object from the XML response stream.
                responseXmlDoc = new XmlDocument();
                responseXmlDoc.Load(responseStream);
                
                
// Clean up.
                responseStream.Close();
                objResponse.Close();
                
                
//responseXmlDoc.Save(@"C:/jjj.xml");
                return responseXmlDoc;

            }

            
catch(Exception e)
            
{
                
throw new Exception("Can't get the data" + e.ToString());
            }
    
        }

        
public XmlDocument GetItemFieldValue(string strBody)
        
{
            
//string strSrcURI = ItemURL;

            
byte[] bytes = null;
            Stream requestStream 
= null;
            Stream responseStream 
= null;
            XmlDocument responseXmlDoc 
= null;
            

            
try
            
{
                
                
// Create the HttpWebRequest object.
                objRequest = (HttpWebRequest)HttpWebRequest.Create(Url);
                
// Add the network credentials to the request.
                objRequest.Credentials = m_Session.Credentials;
                
// Specify the method.
                objRequest.Method = "PROPFIND";
                
//objRequest.Method = "SEARCH";
                
// Encode the body 
                bytes = this.Encode.GetBytes((string)strBody);
                
                
// Set the content header length.  This must be
                
// done before writing data to the request stream.
                objRequest.ContentLength = bytes.Length;

                
// Get a reference to the request stream.
                requestStream = objRequest.GetRequestStream();
                

                
// Write the request body to the request stream.
                requestStream.Write(bytes, 0, bytes.Length);

                
// Close the Stream object to release the connection
                
// for further use.
                requestStream.Close();

                
// Set the content type header.
                objRequest.ContentType = "text/xml";

                
// Send the PROPFIND method request and get the
                
// response from the server.
                objResponse = (HttpWebResponse)objRequest.GetResponse();
                
//return null;

                
// Get the XML response stream.
                responseStream = objResponse.GetResponseStream();

                
// Create the XmlDocument object from the XML response stream.
                responseXmlDoc = new XmlDocument();
                responseXmlDoc.Load(responseStream);
                
                
// Clean up.
                responseStream.Close();
                objResponse.Close();
                responseXmlDoc.Save(
@"C:/jjj.xml");
                
return responseXmlDoc;

            }

            
catch(Exception e)
            
{
                
throw new Exception("Can't get the data" + e.ToString());
            }
            
        }

        
/// <summary>
        
/// 删除一个item
        
/// </summary>
        
/// <param name="itemUrl"></param>

        public void DeleteItem(string itemUrl)
        
{
            
try
            
{
                objRequest 
= (System.Net.HttpWebRequest)HttpWebRequest.Create(itemUrl);

                
// Add the network credentials to the request.
                objRequest.Credentials = this.Session.Credentials;

                
// Specify the DELETE method.
                objRequest.Method = "DELETE";

                
// Send the DELETE method request.
                objResponse = (System.Net.HttpWebResponse)objRequest.GetResponse();

                
// Close the HttpWebResponse object.
                objResponse.Close();

                
//Console.WriteLine("Item successfully deleted.")

            }

            
catch(Exception e)
            
{
                
throw new Exception("Can't delete the item" + e.ToString());

            }

        }

        
/// <summary>
        
/// create a subfolder
        
/// </summary>
        
/// <param name="strBody"></param>

        public void CreateFolder(string folderName)
        
{
            
//string strSrcURI = ItemURL;
            try
            
{
                
// Create the HttpWebRequest object.
                objRequest = (HttpWebRequest)HttpWebRequest.Create(Url + "/" + folderName);
                
// Add the network credentials to the request.
                objRequest.Credentials = m_Session.Credentials;
                
// Specify the method.
                objRequest.Method = "MKCOL";

                objResponse 
= (System.Net.HttpWebResponse)objRequest.GetResponse();

                
// Close the HttpWebResponse object.
                objResponse.Close();
                
            }

            
catch(Exception e)
            
{
                
throw new Exception("Can't create the foder" + e.ToString());
            }
            
        }

//        public DataSet GetDataFromXmlDocument(XmlDocument xml)
//        {
//            XmlDocument xd = new XmlDocument();
//            xd.LoadXml("<myroot>" + FieldStr + "</myroot>");
//            XPathNavigator xpn = xd.CreateNavigator();
//            XPathNodeIterator ni = xpn.Select("/myroot/Field");
//            while (ni.MoveNext())
//            {
//                SpsExpendFieldData objFieldData = SpsExpendFieldData.Create(ni.Current.GetAttribute("Name",""),
//                    ni.Current.GetAttribute("ColName",""),
//                    0,
//                    ni.Current.GetAttribute("Type",""));
//                result.Add(objFieldData);
//            }
//            return result;
//        }
    }

}



WebExchange obj = new WebExchange(WebDavSession.GetSession(ISoftStone.AccessExchange.WebDav.User.GetUser("jianli","password","iisdnet"),
                
"http://10.10.10.10/exchange/jianli/日历"));

            System.Text.StringBuilder sb 
= new System.Text.StringBuilder();
            sb.Append(
" <?xml version=/"1.0/"?>");
            sb.Append(
" <D:searchrequest xmlns:D = /"DAV:/" >");
            sb.Append(
" <D:sql>");
            sb.Append(
" SELECT /"DAV:displayname/"");
            sb.Append(
" ,/"DAV:href/" ");
            sb.Append(
",/"urn:schemas:calendar:dtstart/" ");
            sb.Append(
",/"urn:schemas:calendar:dtend/" ");
            sb.Append(
" ,/"urn:schemas:calendar:location/"");
            sb.Append(
",/"urn:schemas:calendar:busystatus/" ");
            sb.Append(
",/"urn:schemas:httpmail:subject/"");
            sb.Append(
" ,/"urn:schemas:httpmail:htmldescription/"" );
            sb.Append(
" FROM  /"http://10.10.10.10/exchange/jianli/日历/"");
            sb.Append(" WHERE /"urn:schemas:calendar:dtstart/" >= '" + this.TBBeginTime.Text.Trim() + "' ");
            sb.Append(
" AND /"urn:schemas:calendar:dtstart/" &lt; '2006-01-01' ");
            sb.Append(
" </D:sql></D:searchrequest> ");


DataSet ds = new DataSet();
            DataTable db 
= new DataTable();
            ds.Tables.Add(db);
            
            ds.Tables[
0].Columns.Add("displayname",System.Type.GetType("System.String"));
            ds.Tables[
0].Columns.Add("href",System.Type.GetType("System.String"));
            ds.Tables[
0].Columns.Add("dtstart",System.Type.GetType("System.DateTime"));
            ds.Tables[
0].Columns.Add("dtend",System.Type.GetType("System.DateTime"));
            ds.Tables[
0].Columns.Add("location",System.Type.GetType("System.String"));
            ds.Tables[
0].Columns.Add("busystatus",System.Type.GetType("System.String"));
            ds.Tables[
0].Columns.Add("subject",System.Type.GetType("System.String"));
            ds.Tables[
0].Columns.Add("htmldescription",System.Type.GetType("System.String"));
            
//ds.Tables[0].Columns.Add("href",System.Type.GetType("System.String"));

            XmlDocument xd;
            
//xd.Load(@"C:/jjj.xml");
            xd = obj.SearchItems(sb.ToString());
        

            XPathNavigator xpn 
= xd.CreateNavigator();
            XPathExpression expr 
= xpn.Compile("//a:multistatus/a:response/a:propstat/a:prop");
            XmlNamespaceManager nsmgr 
= new XmlNamespaceManager(xpn.NameTable);
            nsmgr.AddNamespace(
"a","DAV:");
            nsmgr.AddNamespace(
"d","urn:schemas:calendar:");
            expr.SetContext(nsmgr);

            XPathNodeIterator ni 
= xpn.Select(expr);
            Response.Write(ni.Count);
            
while (ni.MoveNext())
            
{
                
                
//if(ni.Current.Value != "")
                {
                    DataRow row 
= ds.Tables[0].NewRow();
                    XPathNodeIterator mi 
= ni.Current.SelectChildren("displayname","DAV:");
                    
while(mi.MoveNext())
                    
{
                        row[
"displayname"] = mi.Current.Value;
                        
//Response.Write("[" + mi.Current.Value + "]");
                    }

                    mi 
= null;
                    mi 
= ni.Current.SelectChildren("href","DAV:");
                    
while(mi.MoveNext())
                    
{
                        row[
"href"] = mi.Current.Value;
                        
//Response.Write("[" + mi.Current.Value + "]");
                    }

                    mi 
= null;
                    mi 
= ni.Current.SelectChildren("dtstart","urn:schemas:calendar:");
                    
while(mi.MoveNext())
                    
{
                        row[
"dtstart"] = (Convert.ToDateTime(mi.Current.Value));
                        
//Response.Write("[" + mi.Current.Value + "]");
                    }

                    mi 
= null;
                    mi 
= ni.Current.SelectChildren("dtend","urn:schemas:calendar:");
                    
while(mi.MoveNext())
                    
{
                        row[
"dtend"] = (Convert.ToDateTime(mi.Current.Value));//.AddHours(8);
                        
//Response.Write("[" + mi.Current.Value + "]");
                    }

                    mi 
= null;
                    mi 
= ni.Current.SelectChildren("location","urn:schemas:calendar:");
                    
while(mi.MoveNext())
                    
{
                        row[
"location"] = mi.Current.Value;
                        
//Response.Write("[" + mi.Current.Value + "]");
                    }

                    mi 
= null;
                    mi 
= ni.Current.SelectChildren("busystatus","urn:schemas:calendar:");
                    
while(mi.MoveNext())
                    
{
                        row[
"busystatus"] = mi.Current.Value;
                        
//Response.Write("[" + mi.Current.Value + "]");
                    }

                    mi 
= null;
                    mi 
= ni.Current.SelectChildren("subject","urn:schemas:httpmail:");
                    
while(mi.MoveNext())
                    
{
                        row[
"subject"] = mi.Current.Value;
                        
//Response.Write("[" + mi.Current.Value + "]");
                    }

                    mi 
= null;
                    mi 
= ni.Current.SelectChildren("htmldescription","urn:schemas:httpmail:");
                    
while(mi.MoveNext())
                    
{
                        row[
"htmldescription"] = mi.Current.Value;
                        
//Response.Write("[" + mi.Current.Value + "]");
                    }

                    ds.Tables[
0].Rows.Add(row);
                }


                
//                SpsExpendFieldData objFieldData = SpsExpendFieldData.Create(ni.Current.GetAttribute("Name",""),
                
//                    ni.Current.GetAttribute("ColName",""),
                
//                    0,
                
//                    ni.Current.GetAttribute("Type",""));
                
//                result.Add(objFieldData);
                
            }

exchange日历中的字段列表

最近工作中遇到些烦心的事,郁闷了好几天总也开心不起来,现在想通了

开心就好
人事管理系统c语言程序 很好的程序哦 void cake(int array[ ],int N) { int i,j,t,c,lastexchange; struct student temp; lastexchange=N-1; while(lastexchange) { for(i=0,c=0;i<lastexchange;i++) if(array[i]>array[i+1]) {t=array[i+1]; array[i+1]=array[i]; array[i]=t; temp=stu[i+1];stu[i+1]=stu[i];stu[i]=temp; c=i+1; } lastexchange=c; } 立即下载

相关推荐

邮件发送,支持exchange类型 jar包

邮件发送,支持普通邮件以及exchange类型的邮件发送,包含需要的jar包

C中void exchange()的使用

void exchange()的作用是对函数值的交换 #include<stdio.h> void exchange(int *i,int *j); void main() { int i=1,j=2,k,n; printf("%d,%d\n",i,j); exchange(&i,&j); printf("%d,%d\n",i,j); ge...

qq_18671205的博客 6431

5G R18标准:AI/ML如何重塑空口优化与网络架构

人工智能与机器学习正逐步成为通信网络优化的核心技术。其核心原理在于通过数据驱动模型,从海量网络数据中学习信道变化、用户行为等统计规律,替代传统的基于固定规则的优化方法。这一技术范式能显著提升网络性能与效率,尤其在空口资源管理、干扰协调和能耗控制等场景中价值突出。在5G Advanced(R18)标准化框架下,AI/ML被系统性地引入空口设计,聚焦于信道状态信息反馈增强、波束管理与预测等关键用例。通过定义网络侧AI、终端侧AI及联合学习的标准化接口与流程,R18旨在实现跨厂商设备的智能协同,推动无线网络向自适

weixin_35671843的博客 253

Spring Cloud Gateway 实现全局过滤器 GlobalFilter

哈喽,今天我们来简单说说如何实现Gateway的全局过滤器 前面说了,Gateway主要的作用有路由转发,鉴权,打印日志等功能,今天我们来说说如何基于全局过滤器,来实现打印日志功能。 首先,我们还是来看看项目机构: 可以看到,结构还是之前实现Gateway项目那样,文章点击这里,只是增加了一个实现全局过滤器的filter,逻辑如下图所示: package com.tony.cloudgateway.config; import cn.hutool.core.date.DateUtil; im

a724826175的博客 2581

NSGA-III相关笔记

NSGA-III目录目的区别NSGA-III的算法流程非支配排序详解归一化详解 目录 NSGA-III基于matlab的实现 参考文献 1.An Evolutionary Many-Objective Optimization Algorithm Using Reference-point Based Non-dominated Sorting Approach,Part I: Solving P...

weixin_42555400的博客 1万+

博图软件V15.1安装教程

博途软件安装

m0_46266496的博客 1万+

在C#中通过webdav操作exchange

操作exchange类库代码 为日历中的约会定义的实体 usingSystem; usingSystem.Collections; namespaceISoftStone.AccessExchange.WebDav { /**////<summary> ///CalendarItemInfo的摘要说明。 ...

a859501的博客 327

《UDS协议从入门到精通》系列——图解0x23:通过地址读取内存

如何读取ECU中指定内存地址的数据?图解UDS 0x23服务带你快速上手!!

车载系统攻城狮 2628

通过Powershell操作Exchange/Lync Service 2010

      最近在做两个项目:邮箱管理系统和Lync开户系统。其中邮件管理系统主要对 Exchange Service上的邮箱和群组进行管理,邮箱(MailBox)管理包括创建邮箱、禁用邮箱、删除邮箱、设置主地址等功能,群组 (DistributionGroup)管理包括创建/删除群组、添加/删除群组成员、添加/删除群组白名单等;Lync开户系统主要是为邮箱开通使用 Microsoft...

初出茅庐 656

【教程4>第8章>第44节】本章整体思维导图与学习总结

本教程系列提供FPGA/MATLAB/Simulink学习资源,包含《MATLAB入门100例》、《FPGA入门100例》、《Simulink入门60例》等基础教程,以及《FPGA/MATLAB/Simulink联合开发》进阶教程和《人工智能基础应用研究》专题,适合不同层次的学习者系统掌握相关技术。

FPGA/MATLAB学习教程/源码/项目合作开发 456

用 SAP-ABAP-1 把 ABAP 代码理解这件事交给 AI:从遗留代码到 ABAP Cloud 的开发加速器

SAP-ABAP-1是SAP推出的首个专用ABAP基础模型,专注于理解和解释ABAP代码,帮助开发者更快迁移和维护遗留系统。它强调ABAP Cloud合规编码实践,通过SAP AI Foundation提供访问,主要能力包括代码解释、业务语义理解和框架约束分析。相比通用模型,它能更好处理ABAP特有的版本差异、权限控制和扩展边界等问题。该模型可集成到多种开发环境中,支持文件化开发体验,并能与SAP Joule等工具协同工作,为ABAP团队提供智能辅助。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 3834

使用Python自动化管理Exchange邮箱

Python是一种解释型、交互式、面向对象的编程语言,不但简单、开源、可移植,而且拥有丰富的Python官方和第三方类库。这些类库的底层代码不一定都是Python,还有很多C/C++的身影。通过C/C++语言实现的代码可以在Python中被调用。所以Python也被称为“胶水语言”。基于Python的强大类库,我们可以实现诸如Web开发,自动化管理,数据分析,机器学习等各种功能。今天我要介绍的是如何借助Python的Exchangelib库轻松实现Exchange邮箱的自动化管理。重点介绍邮箱中的邮件数据

4014

【蓝牙协议栈】【BLE】详解蓝牙BLE连接建立过程

advertiser。发出广播的设备observer或者scanner。可以扫描广播的设备initiator。能发起连接的设备master或者central。连接成功后的主设备,即主动发起packet的设备slave或者peripheral。连接成功后的从设备,即被动回传packet的设备图11通过时间把observer,initiator和central串起来了,其实这三个角色是相互独立的,也就是说一个设备可以只支持observer角色,而不支持initiator和central角色。

风云说通信 2530

Exchange WebService(EWS)

转载地址:http://lloydsheng.com/2010/03/exchange-webservice-managed-api.html [译] Exchange Web Services Managed API 1.0 入门 LloydSheng 写于 2010年03月5日上午 8:12 | 评论一下 Exchange Web Services Managed API 1....

fanth的专栏 1728

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

Sharepoint应用EWSManagedAPI操作Exchange邮箱

在sharepoint定制开发中,可能会有读取用户邮件并显示的Webpart需求, 本文是对如何使用EWS Managed API操作Exchange邮箱进行的整理和总结。 一、认识EWS Managed API EWS Managed API是微软开发用于客户端开发Exchange的应用程序接口,与.Net Framework 类库一样,简单直观的提供Exchange资源的统一访问。

Ryan1221的专栏 837

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

.NET通过PowerShell操作ExChange为用户开通邮箱教程

转:http://www.cnblogs.com/gongguo/archive/2012/03/12/2392049.html ============================================================================== 要使.NET调用PowerShell组建能够管理Exchange必须在调用的时候加载管理模块,否则和Exch...

weixin_30454481的博客 1110

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

.NET通过PowerShell操作ExChange为用户开通邮箱账号

最近工作中一个web项目需要集成exchange邮箱服务,注册用户时需要动态创建邮箱用户,终于在http://www.cnblogs.com/gongguo/archive/2012/03/12/2392049.html中找到了解决方案。但在实现的过程中还是出现了些问题,经过几次尝试终于成功调用。 就自己碰到的问题记录下来共勉。 直接用C#代码访问ExChange不会报错,但不会成功创建邮箱用...

weixin_30484247的博客 483

Exchange Web Services Managed API 1.0 入门

Exchange Web Services Managed API 1.0 大概是在微软在09年10月左右发布的目前国内的资料非常少,国外倒是还有一些比较好的资料。这是一篇入门级的文章,只希望能给大家一个简单的介绍,具体的更详细的大家可以在MSDN里面找。 Exchange在2007之后提供了Exchange Web Service(EWS),它提供了一个访问Exchange资源的全新接口。...

weixin_33851604的博客 624

.net开通exchange邮箱

最近在工作中负责解决 用代码在Exchange中为用户创建邮箱 的问题 主要就是用C#封装一个ExChange操作类,在ExChange的服务器上发布一个WebService  供系统的java代码调用 在查阅很多资料后,终于在 http://www.cnblogs.com/xiaogelove/archive/2011/02/17/1956617.html 这篇帖子的指导下把这个

qq_31148345的博客 2493

adLDAP:强大的PHP类库,实现LDAP与Active Directory无缝集成

adLDAP:强大的PHP类库,实现LDAP与Active Directory无缝集成 adLDAP 是一个采用 PHP 编写的成熟类库,它专为提供 LDAP 身份验证和与微软 Active Directory 的深度整合而设计。该开源项目以其简洁高效的方式,在众多开发者社区中获得了广泛的应用和好评。 核心功能 LDAP认证:支持快速安全的用户登录验证,与AD目录服务紧密集成。 AD管理工具:提...

gitblog_01111的博客 769

[译] Exchange Web Services Managed API 1.0 入门

Exchange Web Services Managed API 1.0 大概是在微软在09年10月左右发布的目前国内的资料非常少,国外倒是还有一些比较好的资料。这是一篇入门级的文章,只希望能给大家一个简单的介绍,具体的更详细的大家可以在MSDN里面找。 Exchange在2007之后提供了Exchange Web Service(EWS),它提供了一个访问Exchange资源的全...

一个标题 677
上一篇: 今天感觉不错
下一篇: 元数据(metadata)在企业应用开发中的作用
codinghello
博客等级 码龄25年 47粉丝 33原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址