
<asp:Label id=Label1 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.importance").ToString()=="1"?"":"<img src=\"images/prio"+DataBinder.Eval(Container, "DataItem.importance")+".gif\">" %>'>
<IFRAME class="ipFlat" id="idHtmlBody" name="idHtmlBody" src="blank.htm" frameBorder="0"
width="100%" height="100%" security="restricted"></IFRAME><TEXTAREA id="idBody" style="DISPLAY: none" runat="server"></TEXTAREA>
XmlNodeList htmldescription=ResponseXmlDoc.GetElementsByTagName("e:htmldescription");
this.idBody.InnerHtml=htmldescription[0].InnerText;
<script language="JavaScript">
function window.onload()

{
var oFrm = document.frames["idHtmlBody"];
g_winDocAll = window.document.all;
oFrm.document.write(g_winDocAll.idBody.value);
oFrm.document.close();
}
</script>
Response = (HttpWebResponse)Request.GetResponse();
// Get the XML response stream.
ResponseStream = Response.GetResponseStream();
// Create the XmlDocument object from the XML response stream.
ResponseXmlDoc = new System.Xml.XmlDocument();
// Load the XML response stream.
ResponseXmlDoc.Load(ResponseStream);
// Get the root node.
root = ResponseXmlDoc.DocumentElement;
// Create a new XmlNamespaceManager.
nsmgr = new System.Xml.XmlNamespaceManager(ResponseXmlDoc.NameTable);
// Add the DAV: namespace, which is typically assigned the a: prefix
// in the XML response body. The namespaceses and their associated
// prefixes are listed in the attributes of the DAV:multistatus node
// of the XML response.
nsmgr.AddNamespace("a", "DAV:");
// Add the http://schemas.microsoft.com/mapi/proptag/ namespace, which
// is typically assigned the d: prefix in the XML response body.
nsmgr.AddNamespace("d", "http://schemas.microsoft.com/mapi/proptag/");
// Use an XPath query to build a list of the DAV:propstat XML nodes,
// corresponding to the returned status and properties of
// the file attachment(s).
PropstatNodes = root.SelectNodes("//a:propstat", nsmgr);
// Use an XPath query to build a list of the DAV:href nodes,
// corresponding to the URIs of the attachement(s) on the message.
// For each DAV:href node in the XML response, there is an
// associated DAV:propstat node.
HrefNodes = root.SelectNodes("//a:href", nsmgr);然而,此时通过HrefNodes[i].InnerText得到的却是形如http://191.0.0.111/exchange/zhouhongying/%E6%94%B6%E4%BB%B6%E7%AE%B1/No%20Subject-7.EML/%E6%A0%B7%E5%93%81.jpg的字符串,也就说中文字符被转换成了UTF8的编码,详细参考见《IIS如何接收ServerXMLHTTP传过来的编码字符》(原作者不详)。那么将分拆的字符串进行码制转换即可。
int index=HrefNodes[i].InnerText.LastIndexOf('/')+1;
string attachmentName=HrefNodes[i].InnerText.Substring(index);
int mLastIndex=attachmentName.LastIndexOf('.');
string mMainName=attachmentName.Substring(0,mLastIndex);
mMainName=Server.UrlDecode(mMainName);
int mExtLength=attachmentName.Length - mLastIndex;
string mExtName= attachmentName.Substring(mLastIndex,mExtLength);
this.LAttachment.Text+="<a href=\"MailAttachment/"+displayname+"/"+mMainName+"."+mExtName+"\" target=\"_blank\">"+mMainName+"."+mExtName+"("+size+")</a> ";
_attachmentName[i]=mMainName+"."+mExtName;
private void GetDateToForm(string displayname)
{
System.Net.HttpWebRequest Request;
System.Net.WebResponse Response;
System.Net.CredentialCache MyCredentialCache;
// string strSrcURI = "http://191.0.0.111/exchange/administrator/收件箱/"+displayname;
// string strUserName = "administrator";
string userID=User.Identity.Name.Trim();
string strSrcURI = "http://191.0.0.111/exchange/"+userID+"/收件箱/"+displayname;
string strUserName = userID;
//string strPassword = "afineday";
string strPassword=DAL.Data.UserModel.SelectByUserId(userID).Password.Trim();
string strDomain = "oa.lgyw";
string strBody = "";
byte[] bytes = null;
System.IO.Stream RequestStream = null;
System.IO.Stream ResponseStream = null;
XmlDocument ResponseXmlDoc = null;
try
{
// Build the PROPFIND request body.
// strBody = "<?xml version=\"1.0\"?>"
// + "<d:propfind xmlns:d='DAV:'><d:prop>"
// + "<d:displayname/></d:prop></d:propfind>";
strBody="<?xml version=\"1.0\"?>"
+ "<d:propfind xmlns:d='DAV:'><d:allprop/>"
+"</d:propfind>";
// Create a new CredentialCache object and fill it with the network
// credentials required to access the server.
MyCredentialCache = new System.Net.CredentialCache();
MyCredentialCache.Add( new System.Uri(strSrcURI),
"NTLM",
new System.Net.NetworkCredential(strUserName, strPassword, strDomain)
);
// Create the HttpWebRequest object.
Request = (System.Net.HttpWebRequest)HttpWebRequest.Create(strSrcURI);
// Add the network credentials to the request.
Request.Credentials = MyCredentialCache;
// Specify the method.
Request.Method = "PROPFIND";
// Encode the body using UTF-8.
bytes = Encoding.UTF8.GetBytes((string)strBody);
// Set the content header length. This must be
// done before writing data to the request stream.
Request.ContentLength = bytes.Length;
// Get a reference to the request stream.
RequestStream = Request.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.
Request.ContentType = "text/xml";
// Send the PROPFIND method request and get the
// response from the server.
Response = (HttpWebResponse)Request.GetResponse();
// Get the XML response stream.
ResponseStream = Response.GetResponseStream();
// Create the XmlDocument object from the XML response stream.
ResponseXmlDoc = new XmlDocument();
ResponseXmlDoc.Load(ResponseStream);
// Build a list of the DAV:href XML nodes, corresponding to the folders
// in the mailbox. The DAV: namespace is typically assgigned the a:
// prefix in the XML response body.
XmlNodeList SenderNodes = ResponseXmlDoc.GetElementsByTagName("e:from");
XmlNodeList ToNodes=ResponseXmlDoc.GetElementsByTagName("e:to");
XmlNodeList CCNodes=ResponseXmlDoc.GetElementsByTagName("d:cc");
XmlNodeList importanceNodes=ResponseXmlDoc.GetElementsByTagName("e:importance");
XmlNodeList sensitivityNodes=ResponseXmlDoc.GetElementsByTagName("d:sensitivity");
XmlNodeList datareceiveNodes=ResponseXmlDoc.GetElementsByTagName("e:datereceived");
XmlNodeList subjectNodes=ResponseXmlDoc.GetElementsByTagName("e:subject");
XmlNodeList htmldescription=ResponseXmlDoc.GetElementsByTagName("e:htmldescription");
XmlNodeList hasattachmentNodes=ResponseXmlDoc.GetElementsByTagName("e:hasattachment");
if(subjectNodes.Count > 0)
{
this.Lfrom.Text=SenderNodes[0].InnerText.Replace("<","<").Replace(">",">");
this.Ldatareceived.Text=DateTime.Parse(datareceiveNodes[0].InnerText).ToString();
this.Lreceive.Text=ToNodes[0].InnerText.Replace("<","<").Replace(">",">");
this.LSubject.Text=subjectNodes[0].InnerText;
if(CCNodes.Count>0)
{
this.LCC.Text=CCNodes[0].InnerText.Replace("<","<").Replace(">",">");
}
if(importanceNodes.Count>0)
{
if(importanceNodes[0].InnerText=="2")
{
this.LImportance.Text="该邮件重要性为高!";
}
else if((importanceNodes[0].InnerText=="0"))
{
this.LImportance.Text="该邮件重要性为低!";
}
}
if(sensitivityNodes.Count>0)
{
if(sensitivityNodes[0].InnerText=="Private")
{
this.Lsensitivity.Text="私人邮件";
}
else if(sensitivityNodes[0].InnerText=="Personal")
{
this.Lsensitivity.Text="个人邮件";
}
else if(sensitivityNodes[0].InnerText=="Company-Confidential")
{
this.Lsensitivity.Text="机密邮件";
}
}
this.idBody.InnerHtml=htmldescription[0].InnerText;
}
if(hasattachmentNodes[0].InnerText=="1")
{
this.GetAttachment(displayname);
}
// Clean up.
ResponseStream.Close();
Response.Close();
}
catch(Exception ex)
{
// Catch any exceptions. Any error codes from the SEARCH
// method request on the server will be caught here, also.
Context.Response.Write(ex.Message);
}
}
private void GetAttachment(string displayname)
{
// Variables.
System.Net.HttpWebRequest Request;
System.Net.WebResponse Response;
System.Net.CredentialCache MyCredentialCache;
string userID=User.Identity.Name.Trim();
string password=DAL.Data.UserModel.SelectByUserId(userID).Password.Trim();
// string strMessageURI = "http://191.0.0.111/exchange/administrator/收件箱/"+displayname;
// string strUserName = "administrator";
string strMessageURI = "http://191.0.0.111/exchange/"+userID+"/收件箱/"+displayname;
string strUserName = userID;
string strPassword = password;
string strDomain = "oa.lgyw";
System.IO.Stream ResponseStream = null;
System.Xml.XmlDocument ResponseXmlDoc = null;
System.Xml.XmlNode root = null;
System.Xml.XmlNamespaceManager nsmgr = null;
System.Xml.XmlNodeList PropstatNodes = null;
System.Xml.XmlNodeList HrefNodes = null;
System.Xml.XmlNode StatusNode = null;
System.Xml.XmlNode PropNode = null;
string[] _attachmentName=null;
System.Xml.XmlNode NameNode=null;
try
{
// Create a new CredentialCache object and fill it with the network
// credentials required to access the server.
MyCredentialCache = new System.Net.CredentialCache();
MyCredentialCache.Add( new System.Uri(strMessageURI),
"NTLM",
new System.Net.NetworkCredential(strUserName, strPassword, strDomain)
);
// Create the HttpWebRequest object.
Request = (System.Net.HttpWebRequest)HttpWebRequest.Create(strMessageURI);
// Add the network credentials to the request.
Request.Credentials = MyCredentialCache;
// Specify the method.
Request.Method = "X-MS-ENUMATTS";
// Send the X-MS-ENUMATTS method request and get the
// response from the server.
Response = (HttpWebResponse)Request.GetResponse();
// Get the XML response stream.
ResponseStream = Response.GetResponseStream();
// Create the XmlDocument object from the XML response stream.
ResponseXmlDoc = new System.Xml.XmlDocument();
// Load the XML response stream.
ResponseXmlDoc.Load(ResponseStream);
// Get the root node.
root = ResponseXmlDoc.DocumentElement;
// Create a new XmlNamespaceManager.
nsmgr = new System.Xml.XmlNamespaceManager(ResponseXmlDoc.NameTable);
// Add the DAV: namespace, which is typically assigned the a: prefix
// in the XML response body. The namespaceses and their associated
// prefixes are listed in the attributes of the DAV:multistatus node
// of the XML response.
nsmgr.AddNamespace("a", "DAV:");
// Add the http://schemas.microsoft.com/mapi/proptag/ namespace, which
// is typically assigned the d: prefix in the XML response body.
nsmgr.AddNamespace("d", "http://schemas.microsoft.com/mapi/proptag/");
// Use an XPath query to build a list of the DAV:propstat XML nodes,
// corresponding to the returned status and properties of
// the file attachment(s).
PropstatNodes = root.SelectNodes("//a:propstat", nsmgr);
// Use an XPath query to build a list of the DAV:href nodes,
// corresponding to the URIs of the attachement(s) on the message.
// For each DAV:href node in the XML response, there is an
// associated DAV:propstat node.
HrefNodes = root.SelectNodes("//a:href", nsmgr);
// Attachments found?
if(HrefNodes.Count > 0)
{
_attachmentName=new string[HrefNodes.Count];
// Display the number of attachments on the message.
// Iterate through the attachment properties.
for(int i=0;i<HrefNodes.Count;i++)
{
// Use an XPath query to get the DAV:status node from the DAV:propstat node.
StatusNode = PropstatNodes[i].SelectSingleNode("a:status", nsmgr);
// Check the status of the attachment properties.
if(StatusNode.InnerText != "HTTP/1.1 200 OK")
{
return;
}
else
{
// Get the CdoPR_ATTACH_FILENAME_W MAPI property tag,
// corresponding to the attachment file name. The
// http://schemas.microsoft.com/mapi/proptag/ namespace is typically
// assigned the d: prefix in the XML response body.
NameNode = PropstatNodes[i].SelectSingleNode("a:prop/d:x3704001f", nsmgr);
// Get the CdoPR_ATTACH_SIZE MAPI property tag,
// corresponding to the attachment file size.
PropNode = PropstatNodes[i].SelectSingleNode("a:prop/d:x0e200003", nsmgr);
string size;
if(Convert.ToInt32(PropNode.InnerText)>1024*1224)
{
size=(Convert.ToInt32(PropNode.InnerText)/(1024*1024)).ToString()+"M";
}
else if(Convert.ToInt32(PropNode.InnerText)>1024)
{
size=(Convert.ToInt32(PropNode.InnerText)/1024).ToString()+"KB";
}
else
{
size=PropNode.InnerText+"B";
}
int index=HrefNodes[i].InnerText.LastIndexOf('/')+1;
string attachmentName=HrefNodes[i].InnerText.Substring(index);
int mLastIndex=attachmentName.LastIndexOf('.');
string mMainName=attachmentName.Substring(0,mLastIndex);
mMainName=Server.UrlDecode(mMainName);
int mExtLength=attachmentName.Length - mLastIndex;
string mExtName= attachmentName.Substring(mLastIndex,mExtLength);
this.LAttachment.Text+="<a href=\"MailAttachment/"+displayname+"/"+mMainName+"."+mExtName+"\" target=\"_blank\">"+mMainName+"."+mExtName+"("+size+")</a> ";
_attachmentName[i]=mMainName+"."+mExtName;
}
}
} 
// Clean up.
ResponseStream.Close();
Response.Close();
}
catch(Exception ex)
{
// Catch any exceptions. Any error codes from the X-MS-ENUMATTS
// method request on the server will be caught here, also.
}
this.GetAttachmentFile(displayname,HrefNodes.Count,_attachmentName);
}