开发环境:VSTS2005;
开发语言:C#;
开发工程:ASP.NETWeb Application
1 工程引用Batch库。
引用库为:Batch.dll、OpenContactsNet.dll、Utilities.dll、XihSolutions.DotMSN.dll
(这些库都可在我的Demo文件Bin目录下获取)
2 使用Batch库代码
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using Batch;
- using System.Collections.Generic;
- using System.Reflection;
- namespace MSNFriendsDemo
- {
- public partial class _Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- // 获取MSN好友
- List<Batch.Entity.MsnFriend> list = GetMSNFriends("MSN账户", "MSN账户密码");
- // 把MSN好友信息转换为DataTable格式
- DataTable dt = this.ToDataTable(list);
- GridView1.DataSource = dt;
- GridView1.DataBind();
- // 获取Gmail邮箱的联系人
- List<string> LinkmanList = GetGmailFriends("Gmail/Yahoo/Live邮箱帐号", "邮箱密码");
- }
- /// <summary>
- /// 获取指定MSN账户的好友信息
- /// </summary>
- /// <param name="msnUsername">MSN帐户</param>
- /// <param name="msnPassword">MSN账户密码</param>
- /// <returns>MSN好友信息列表</returns>
- private List<Batch.Entity.MsnFriend> GetMSNFriends(string msnUsername,string msnPassword)
- {
- List<Batch.Entity.MsnFriend> list = null;
- try
- {
- // 初始化
- Batch.Helper.MsnHelper helper = new Batch.Helper.MsnHelper();
- // 打开指定的MSN账户
- helper.Start(msnUsername, msnPassword);
- // 获取好友信息
- list = helper.getFriends();
- }
- catch (Exception ex)
- {
- list = new List<Batch.Entity.MsnFriend>();
- }
- return list;
- }
- /// <summary>
- /// 获取Gmail邮箱的联系人(Yahoo邮箱、Live邮箱同Gmail邮箱处理)
- /// </summary>
- /// <param name="gmailUsername">邮箱的用户名</param>
- /// <param name="gmailPassword">邮箱的密码</param>
- /// <returns>邮箱联系人列表信息</returns>
- private List<string> GetGmailFriends(string gmailUsername, string gmailPassword)
- {
- List<string> list = null;
- try
- {
- Batch.Helper.GmailHelper helper = new Batch.Helper.GmailHelper();
- list = helper.getLinkmans(gmailUsername, gmailPassword);
- }
- catch (Exception ex)
- {
- list = new List<string>();
- }
- return list;
- }
- /// <summary>
- /// 把MSN好友信息转换为DataTable格式
- /// </summary>
- /// <param name="list">MSN好友信息List</param>
- /// <returns>格式化后的DataTable</returns>
- private DataTable ToDataTable(List<Batch.Entity.MsnFriend> list)
- {
- DataTable result = new DataTable();
- if (list.Count > 0)
- {
- PropertyInfo[] propertys = list[0].GetType().GetProperties();
- foreach (PropertyInfo pi in propertys)
- {
- result.Columns.Add(pi.Name, pi.PropertyType);
- }
- for (int i = 0; i < list.Count; i++)
- {
- ArrayList TempList = new ArrayList();
- foreach (PropertyInfo pi in propertys)
- {
- object obj = pi.GetValue(list[i], null);
- TempList.Add(obj);
- }
- object[] array = TempList.ToArray();
- result.LoadDataRow(array, true);
- }
- }
- return result;
- }
- }
- }