首页 > 编程 > .NET > 正文

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

2024-07-10 13:09:36
字体:
来源:转载
供稿:网友

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.

注册会员,创建你的web开发资料库,
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表