none
Sharepoint 2007与outlook或exchange集成 ,并且很着急的问题,那问大兄帮帮忙! RRS feed

  • 问题

  •  我想在Sharepoint中作个webpart用来显示 outlook中未读的邮件的数量,然后点击连接打开outlook, ..........

    我遇到的问题是.我写了一个方法,去读取,但一定要提供秘密(域账户密码).... 请问是否可以自动获取再sharepoint中. ,代码如下:

     

           public int GetUnReadMailCount(string userName, string password, string exchangeUrl, string domain)
            {
                System.Net.HttpWebRequest Request;
                System.Net.WebResponse Response;
                System.Net.CredentialCache MyCredentialCache;
                string strRootURI = exchangeUrl + userName; //得到要访问邮箱的WebDAV地址
                string strQuery = "";
                byte[] bytes = null;
                System.IO.Stream RequestStream = null;
                System.IO.Stream ResponseStream = null;
                XmlDocument ResponseXmlDoc = null;
                XmlNodeList HrefNodes = null;
                XmlNodeList SizeNodes = null;
                int count = 0;
                try
                {
                    //SPWeb myWeb = SPContext.Current.Web;
                    //string kkk = myWeb.CurrentUser.Email;
                    //kkk = myWeb.CurrentUser.ToString();
                    //string sss="highly\\lucasc";
                    //MembershipUser u = Membership.GetUser(sss, false);
                    //u.GetPassword();
                    //kkk = u.GetPassword();
                    // 用SQL查询WebDAV返回结果中的unreadcount节点.
                    strQuery = "<?xml version=\"1.0\"?><D:searchrequest xmlns:D = \"DAV:\" >"
                         + "<D:sql>SELECT \"DAV:displayname\",\"urn:schemas:httpmail:unreadcount\" FROM \"" + strRootURI + "\""
                       + "</D:sql></D:searchrequest>";
                    //创建新的CredentialCache对象,构建身份凭据
                    MyCredentialCache = new System.Net.CredentialCache();
                    MyCredentialCache.Add(new System.Uri(strRootURI), "Basic",
                    new System.Net.NetworkCredential(userName, password, domain));
                    // Create the HttpWebRequest object.
                    Request = (System.Net.HttpWebRequest)HttpWebRequest.Create(strRootURI);
                    // 指定HttpWebRequest的身份凭据,此处为关键所在。如果使用之前
                    // 创建的MyCredentialCache,则这个身份凭据是可以从Web服务器传递
                    // 到Exchange服务器的,但是这样带来的问题也很明显,就是不能够自
                    // 动获取当前登录到域的用户的身份。即便已经成功登录到域,那也只
                    // 能通过form再次输入用户名密码。因此,我在这里用的是
                    // 这样便可以获得当前用户的凭据,但是这样带来的问题便是上面提到的
                    // 身份凭据无法传递的问题,解决方法请关注下篇文章。
                    Request.Credentials = MyCredentialCache;
                    // 指定WebDAV的SEARCH方法
                    Request.Method = "SEARCH";
                    // Encode the body using UTF-8.
                    bytes = Encoding.UTF8.GetBytes((string)strQuery);
                    // 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 SQL query 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 SEARCH method request and get the
                    // response from the server.
                    Response = (HttpWebResponse)Request.GetResponse();
                    // Get the XML response stream.
                    ResponseStream = Response.GetResponseStream();
                    // 创建XmlDocument对象,并获取收件箱的unreadcount节点的值
                    ResponseXmlDoc = new XmlDocument();
                    ResponseXmlDoc.Load(ResponseStream);
                    HrefNodes = ResponseXmlDoc.GetElementsByTagName("a:displayname");
                    SizeNodes = ResponseXmlDoc.GetElementsByTagName("d:unreadcount");
                    for (int i = 0; i < HrefNodes.Count; i++)
                    {
                        if (HrefNodes[i].InnerText == "收件箱")
                            count = int.Parse(SizeNodes[i].InnerText);
                    }
                    ResponseStream.Close();
                    Response.Close();


    Reed
    2010年9月9日 6:38

全部回复