csharp Send Skype messages from webform and winform

简介: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using SKYPE4COMLib; //下載地址:http
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using SKYPE4COMLib; //下載地址:http://en.sourceforge.jp/projects/sfnet_skype4mp/downloads/Skype4MP/obj/Release/Interop.SKYPE4COMLib.dll/


namespace ListBoxDemo
{
    /// <summary>
    /// skype 發送信息,也可以用在WinForm
    /// Geovin Du 塗聚文
    /// 締友計算機信息技術有限公司
    /// 20120725
    /// 
    /// </summary>
    public partial class _Default : System.Web.UI.Page
    {
        string strskypeuser = string.Empty;
        string strskypeid = string.Empty;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                
         
                //1 Geovin Du 塗聚文

                BindSmartListBox();

                //2 Geovin Du 塗聚文

                //this.ListBox1.DataSource = skyuselist();
                //this.ListBox1.DataTextField = "userDisplayName";
                //this.ListBox1.DataValueField = "userLoginName";
                //this.ListBox1.DataBind();
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
            //1
            //strskypeuser = ListBox1.SelectedItem.Text;
            //strskypeid = ListBox1.SelectedValue.ToString();
            //2
            //
            strskypeuser = ListBox1.SelectedItem.Text;
            strskypeid = ListBox1.SelectedValue.ToString();


            this.TextBox2.Text = strskypeid;
            SKYPE4COMLib.Skype oSkype = new SKYPE4COMLib.Skype();

            if (!string.IsNullOrEmpty(strskypeid))
            {

                oSkype.SendMessage(strskypeid, strskypeuser + ":" + this.TextBox1.Text);
            }
            else
            {
                oSkype.SendMessage("ginhongzhao", strskypeuser + ":" + this.TextBox1.Text);
            }
        }
        /// <summary>
        /// 初始化物件,預設會抓本機的Skype帳號資訊
        /// </summary>
        private void BindSmartListBox()
        {
            
            SKYPE4COMLib.Skype oSkype = new SKYPE4COMLib.Skype();
            UserCollection tFriends = oSkype.Friends;
            ListItem li =null;
            foreach (User tUser in oSkype.Friends)
            {
                if (tUser.FullName.Trim() != "")
                {

                    li = new ListItem(tUser.FullName, tUser.Handle);
                    ListBox1.Items.Add(li);
                }
                else
                {
                    li = new ListItem(tUser.Handle, tUser.Handle);
                    ListBox1.Items.Add(li);
                }

            }

        }
        /// <summary>
        /// 初始化物件,預設會抓本機的Skype帳號資訊
        /// </summary>
        /// <returns></returns>
        private DataTable skyuselist()
        {
            DataTable d = new DataTable();
            //初始化物件,預設會抓本機的Skype帳號資訊
            SKYPE4COMLib.Skype oSkype = new SKYPE4COMLib.Skype();
            UserCollection tFriends = oSkype.Friends;
            d.Columns.Add("userLoginName", typeof(string));
            d.Columns.Add("userDisplayName", typeof(string));
            //取出所有的朋友資訊         
            foreach (User tUser in oSkype.Friends)
            {
                if (tUser.FullName.Trim() != "")
                {

                    d.Rows.Add(tUser.Handle, tUser.FullName);
                }
                else
                {
                    d.Rows.Add(tUser.Handle, tUser.Handle);
                }

            }

            return d;
        }
    }
}

目录
相关文章
|
Web App开发 API Windows
一起谈.NET技术,Silverlight实例教程 - Out of Browser的Debug和Notifications窗口
  Silverlight 实例教程索引 Silverlight 实例教程 - Out of Browser开篇 Silverlight 实例教程 - Out of Browser配置,安装和卸载 Silverlight 实例教程 - Out of Browser的自定义应用 Silverligh...
1057 0