分享
 
 
 

在asp.net 页面中加入skype功能

王朝asp·作者佚名  2008-05-30
窄屏简体版  字體: |||超大  

This sample shows how to use Skype features in your ASP.NET 2.0 website. Based upon the Skype user name and standard phone number, you type in the appropriate fields. Six LinkButtons are populated with the strings that Skype needs in a website to do the basic actions, which are:

Make a Skype call via Skype.

Request contact information.

Start a chat.

Send a file via Skype.

Add a contact.

Make a Skype Out Call.

Creating this sample

I started this sample by creating a new empty website, selected the Add New Item Under Website option, and selected a new WebUserControl to add to my application that I called SkypeSample (it gets the .ascx extension after creation). On this WebsUserControl, I created the following controls:

A Label with the Text property Skype Name

A Label with the Text property Phone Nr

A TextBox with the ID txtSkypeName

A TextBox with the ID txtPhoneNr

A Button called Button1 by default, with the Text property set to Populate

Six LinkButtons called, by default, Linkbutton1...

Six standard type Images called, by default, Image1...

Further, I have added a folder Images to the project, and downloaded a set of images developers can use from the Skype website (Click here to download the images), and chosen the buttons I needed, and added them to the created image map. I set the path of my controls Image1 to Image6 to the appropriate image in my Images folder.

For Button1, I created an event called Populate_Click, and the following code that will fire the method SetSkypeStatus that I created later on.

//Get Spype Status

try

{

this.SetSkype();

}

catch

{

//

}

finally

{

//

}

Then I clicked on the UserControl to go to the code-behind, and created a method called SetSkype and the needed strings for the application.

protected void SetSkype()

{

//Set the Images on the website to unvisible

Image1.Visible = true;

Image2.Visible = true;

Image3.Visible = true;

Image4.Visible = true;

Image5.Visible = true;

Image6.Visible = true;

//Create the Strings that will hold

//the needed values and actions

string SkypeName = txtSkypeName.Text;

string LandPhone = txtPhoneNr.Text;

string PathSkypeStatusString = "";

string SkypeAddContactString = "";

string SkypeCallString = "";

string SkypeLandCall = "";

string SkypeChattString = "";

string SkypeProfileString = "";

string SkypeSendFileString = "";

To populate the strings with values, I created try blocks. The first block gets the status of the Skype user name that is typed in after the method is fired. As you can see in the code below, I created three strings (s1, s2, sT); the last one of the three in the first try block stands for the string total since I tried to create a string I can use to get the status of the Skype contact. As you can see below, the first part of the string is a URL that says where to look, and what icon to use. You could change the word "mediumicon" to, for example, "largeicon", and a large icon will be shown. The string sT= part in this block sets the actual value of the string sT to the string I want, the path to look plus the Skype user name I want the status of. The value sT holds is then passed to the above created PathSkypeStatusString; and I assign PathSkypeStatusString as the value of the Image1 URL, so at runtime, this image should show a medium icon with the current status of the user.

//Get Spype Status

try

{

string s1 = "http://mystatus.skype.com/mediumicon/";

string s2 = SkypeName;

string sT = s1 + s2;

PathSkypeStatusString = sT;

Image1.ImageUrl = PathSkypeStatusString;

}

catch

{

//

}

finally

{

//

}

In the next part, I need more strings because the Skype user name will be in the middle of the string, so creating the complete string is a little more complicated. s4 is important in this part because that is the action that will be performed at runtime, and s6 in the text that will be visible in the LinkButton. Again, I create the string sT, pass the value to SkypeCallString, and set the value of LinkButton1 to the content of SkypeCallString, so at runtime, this Linkbutton will initiate the call when clicked. In the code, the HREF value is seen with no closing tag because that one is later added when I set the value of the string s6.

//Set CallString

try

{

//string s1 = "see code";

string s2 = "skype:";

string s3 = SkypeName;

string s4 = "?call";

string s5 = '"'.ToString();

string s6 = ">Skype Me";

string sT = s1 + s2 + s3 + s4 + s5 + s6;

SkypeCallString = sT;

LinkButton1.Text = SkypeCallString;

}

catch

{

//Todo

}

finally

{

//Todo

}

I repeat this for all the actions that can be performed by the user, setting the values of the LinkButtons to the actions I want them to perform. It's clear why the different actions always look like ?call, ?chat etc.

Running the sample code

To run the sample code, you just open the SkypeSample folder with Visual Studio, under the menu option File, Open, and the select the website. The code should be loaded, and when you hit F5, the sample application should run.

Further use

This sample is easy to use dynamically when you store the Skype user name and phone number in a database and present these values in your website, with, for example, a DetailControl that you load with a data source. When you set the Skype user name and phone number as DataKeys for the DetailControl, you can use the values they hold at runtime for populating the strings (Skype user name and phone number). Below is a sample that shows how you could set the properties from Skype.

//Set SkypeName and SkypeLandCall string values dynamically

try

{

//Set String SkypeName

string SkypeName = DetailsView1.DataKey["Skype"].ToString();

//Set string SkypeLandCall

string SkypeLandCall = DetailsView1.DataKey["CompanyPhone"].ToString();

}

catch

{

//Todo

}

finally

{

//Todo

}

Points of Interest

I am not saying that the code is perfect but it works well from my laptop. When I request the website from my local server, all Skype options work. The name Skype is copyright of Skype Limited.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有