操作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

{

Fields#region Fields
private string m_UserMailUrl;
private ICredentials m_Credentials;
private WebProxy m_Proxy;
#endregion

Property#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 + ";章清平 <qpzhang@iisdnet.com >></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/
"
< '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日历中的字段列表
最近工作中遇到些烦心的事,郁闷了好几天总也开心不起来,现在想通了
开心就好