日期:2010-11-17  浏览次数:20571 次

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<