1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Web; 5 using System.Web.UI; 6 using System.Web.UI.WebControls; 7 using System.Data; 8 using SKYPE4COMLib; //下載地址:http://en.sourceforge.jp/projects/sfnet_skype4mp/downloads/Skype4MP/obj/Release/Interop.SKYPE4COMLib.dll/ 9 10 11 namespace ListBoxDemo 12 { 13 /// <summary> 14 /// skype 發送信息,也可以用在WinForm 15 /// Geovin Du 塗聚文 16 /// 締友計算機信息技術有限公司 17 /// 20120725 18 ///官網下址:https://developer.skype.com/accessories/skype4com 19 /// </summary> 20 public partial class _Default : System.Web.UI.Page 21 { 22 string strskypeuser = string.Empty; 23 string strskypeid = string.Empty; 24 /// <summary> 25 /// 26 /// </summary> 27 /// <param name="sender"></param> 28 /// <param name="e"></param> 29 protected void Page_Load(object sender, EventArgs e) 30 { 31 if (!Page.IsPostBack) 32 { 33 34 35 //1 Geovin Du 塗聚文 36 37 BindSmartListBox(); 38 39 //2 Geovin Du 塗聚文 40 41 //this.ListBox1.DataSource = skyuselist(); 42 //this.ListBox1.DataTextField = "userDisplayName"; 43 //this.ListBox1.DataValueField = "userLoginName"; 44 //this.ListBox1.DataBind(); 45 } 46 } 47 /// <summary> 48 /// 49 /// </summary> 50 /// <param name="sender"></param> 51 /// <param name="e"></param> 52 protected void Button1_Click(object sender, EventArgs e) 53 { 54 //1 55 //strskypeuser = ListBox1.SelectedItem.Text; 56 //strskypeid = ListBox1.SelectedValue.ToString(); 57 //2 58 // 59 strskypeuser = ListBox1.SelectedItem.Text; 60 strskypeid = ListBox1.SelectedValue.ToString(); 61 62 63 this.TextBox2.Text = strskypeid; 64 SKYPE4COMLib.Skype oSkype = new SKYPE4COMLib.Skype(); 65 66 if (!string.IsNullOrEmpty(strskypeid)) 67 { 68 69 oSkype.SendMessage(strskypeid, strskypeuser + ":" + this.TextBox1.Text); 70 } 71 else 72 { 73 oSkype.SendMessage("ginhongzhao", strskypeuser + ":" + this.TextBox1.Text); 74 } 75 } 76 /// <summary> 77 /// 初始化物件,預設會抓本機的Skype帳號資訊 78 /// </summary> 79 private void BindSmartListBox() 80 { 81 82 SKYPE4COMLib.Skype oSkype = new SKYPE4COMLib.Skype(); 83 UserCollection tFriends = oSkype.Friends; 84 ListItem li =null; 85 foreach (User tUser in oSkype.Friends) 86 { 87 if (tUser.FullName.Trim() != "") 88 { 89 90 li = new ListItem(tUser.FullName, tUser.Handle); 91 ListBox1.Items.Add(li); 92 } 93 else 94 { 95 li = new ListItem(tUser.Handle, tUser.Handle); 96 ListBox1.Items.Add(li); 97 } 98 99 } 100 101 } 102 /// <summary> 103 /// 初始化物件,預設會抓本機的Skype帳號資訊 104 /// </summary> 105 /// <returns></returns> 106 private DataTable skyuselist() 107 { 108 DataTable d = new DataTable(); 109 //初始化物件,預設會抓本機的Skype帳號資訊 110 SKYPE4COMLib.Skype oSkype = new SKYPE4COMLib.Skype(); 111 UserCollection tFriends = oSkype.Friends; 112 d.Columns.Add("userLoginName", typeof(string)); 113 d.Columns.Add("userDisplayName", typeof(string)); 114 //取出所有的朋友資訊 115 foreach (User tUser in oSkype.Friends) 116 { 117 if (tUser.FullName.Trim() != "") 118 { 119 120 d.Rows.Add(tUser.Handle, tUser.FullName); 121 } 122 else 123 { 124 d.Rows.Add(tUser.Handle, tUser.Handle); 125 } 126 127 } 128 129 return d; 130 } 131 } 132 }
Download of Interop.SKYPE4COMLib.dll http://en.sourceforge.jp/projects/sfnet_skype4mp/downloads/Skype4MP/obj/Release/Interop.SKYPE4COMLib.dll/