Set-new-picture-in-VCard - WeOnlyDo Software example code



All

wodCrypt (12)
wodSSH (10)
wodSFTP (23)
wodSSHServer (1)
wodSSHTunnel (11)
wodSSHpackage
wodSFTPdll

wodSSH.NET (10)
wodSFTP.NET (24)
wodFtpDLX.NET (22)
wodWebServer.NET (10)

wodAppUpdate (13)
wodHttpDLX (8)
wodFtpDLX (22)
wodTelnetDLX
wodFTPServer (3)
wodWebServer (10)
wodVPN
wodXMPP (13)
All ** [Visual Basic] ** [C#] ** [VB.NET] **

Set new picture in VCard
VB code
Dim WithEvents wodXMPP1 As wodXMPPCom
Private Sub Form_Load()
    Set wodXMPP1 = New wodXMPPCom
    
    wodXMPP1.Login = "JID__username@domain.com"
    wodXMPP1.Password = "JID__password"
    'Connect to Jabber/XMPP server.
    wodXMPP1.Connect
End Sub

'Connected Event fires when wodXMPP connects to remote server.
Private Sub wodXMPP1_Connected()
    'When Connected Event is fired, we can send new picture to server.
'In this example we will do that using button on our form (check Command1_Click).
'Picture will be loaded in PictureBox Control which should be added to your form.
'Using Command2_Click and VCardDetails Event we can check for current VCard picture
. MsgBox "Connected" End Sub 'Disconnected Event fires when wodXMPP disconnects from server. Private Sub wodXMPP1_Disconnected(ByVal ErrorCode As Long, ByVal ErrorText As String) 'Inside Disconnected Event we can check for an error using ErrorText and ErrorCode variable. If ErrorCode <> 0 Then MsgBox "Error: " & ErrorText End If End Sub Private Sub Command1_Click() 'Load picture your want to use in your VCard in a PictureBox Control. Set Picture1.Picture = LoadPicture("c:\some_picture.jpg") 'Set picture from PictureBox to wodXMPP Photo Property. wodXMPP1.VCard.Photo = Picture1.Picture 'Send new picture to server. wodXMPP1.VCard.Send End Sub Private Sub Command2_Click() 'Using receive we can receive VCard details from server. wodXMPP1.VCard.Receive End Sub 'VCardDetails Event fires when someone's VCard arrives from the server. Private Sub wodXMPP1_VCardDetails(ByVal Contact As WODXMPPCOMLib.IXMPPContact, ByVal Partial As Boolean) 'Inside VCardDetails Event we can receive new picture from server and load it in PictureBox. Picture1.Picture = wodXMPP1.VCard.Photo End Sub
VB.NET code
Dim WithEvents wodXMPP1 As WODXMPPCOMLib.wodXMPPCom
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    wodXMPP1 = New WODXMPPCOMLib.wodXMPPCom

    wodXMPP1.Login = "JID__username@domain.com"
    wodXMPP1.Password = "JID__password"
    'Connect to Jabber/XMPP server.
    wodXMPP1.Connect()
End Sub

'Connected Event fires when wodXMPP connects to remote server.
Private Sub wodXMPP1_Connected() Handles wodXMPP1.Connected
'When Connected Event is fired, we can send new picture to server.
'In this example we will do that using button on our form (check Button1_Click).
'Using Button2_Click and VCardDetails Event we can check for current VCard picture.
'Picture will be loaded in PictureBox Control which should be added to your form.
'In order to load picture for wodXMPP to PictureBox stdole reference (Project -> Add Reference)
'should be added to your project
. MsgBox("Connected") End Sub 'Disconnected Event fires when wodXMPP disconnects from server. Private Sub wodXMPP1_Disconnected(ByVal ErrorCode As Integer, ByVal ErrorText As String) Handles wodXMPP1.Disconnected 'Inside Disconnected Event we can check for an error using ErrorText and ErrorCode variable. If ErrorCode <> 0 Then MsgBox("Error: " & ErrorText) End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Load picture your want to use in your VCard in a FileStream object. Dim fs As New System.IO.FileStream("c:\some_picture.jpg", System.IO.FileMode.Open) Dim b As Byte() = New Byte(fs.Length - 1) {} fs.Read(b, 0, b.Length) fs.Close() Dim arr As System.Array = b 'Set picture loaded in FileStream to wodXMPP PhotoData Property. wodXMPP1.VCard.PhotoData = arr 'Send new picture to server. wodXMPP1.VCard.Send() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 'Using receive we can receive VCard details from server. wodXMPP1.VCard.Receive() End Sub 'VCardDetails Event fires when someone's VCard arrives from the server. Private Sub wodXMPP1_VCardDetails(ByVal Contact As WODXMPPCOMLib.XMPPContact, ByVal [Partial] As Boolean) Handles wodXMPP1.VCardDetails Dim im As System.Drawing.Image 'Inside VCardDetails Event we can receive new picture from server and load it in PictureBox. im = System.Drawing.Image.FromHbitmap(wodXMPP1.VCard.Photo.Handle) PictureBox1.Image = New System.Drawing.Bitmap(im) End Sub
C# code
WODXMPPCOMLib.wodXMPPCom wodXMPP1;
private void Form1_Load(System.Object sender, System.EventArgs e)
{
    wodXMPP1 = new WODXMPPCOMLib.wodXMPPCom();
    wodXMPP1.Connected += new WODXMPPCOMLib._IwodXMPPComEvents_ConnectedEventHandler(wodXMPP1_Connected);
    wodXMPP1.Disconnected += new WODXMPPCOMLib._IwodXMPPComEvents_DisconnectedEventHandler(wodXMPP1_Disconnected);
    wodXMPP1.VCardDetails += new WODXMPPCOMLib._IwodXMPPComEvents_VCardDetailsEventHandler(wodXMPP1_VCardDetails);

    wodXMPP1.Login = "JID__username@domain.com";
    wodXMPP1.Password = "JID__password";
    //Connect to Jabber/XMPP server.
    wodXMPP1.Connect(null);
}

//Connected Event fires when wodXMPP connects to remote server.
private void wodXMPP1_Connected()
{
//In this example we will do that using button on our form (check button1_Click).
//Using button2_Click and VCardDetails Event we can check for current VCard picture.
//Picture will be loaded in PictureBox Control which should be added to your form.
//In order to load picture for wodXMPP to PictureBox stdole reference (Project -> Add Reference)
//should be added to your project
. MessageBox.Show("Connected"); } //Disconnected Event fires when wodXMPP disconnects from server. private void wodXMPP1_Disconnected(int ErrorCode, string ErrorText) { //Inside Disconnected Event we can check for an error using ErrorText and ErrorCode variable. if (ErrorCode != 0) { MessageBox.Show("Error: " + ErrorText); } } private void button1_Click(object sender, EventArgs e) { //Load picture your want to use in your VCard in a FileStream object. System.IO.FileStream fs = new System.IO.FileStream(@"c:\some_picture2.jpg", System.IO.FileMode.Open); byte[] b = new byte[fs.Length]; fs.Read(b, 0, b.Length); fs.Close(); //Set picture loaded in FileStream to wodXMPP PhotoData Property. System.Array arr = b; wodXMPP1.VCard.set_PhotoData(ref arr); //Send new picture to server. wodXMPP1.VCard.Send(); } private void button2_Click(object sender, EventArgs e) { //Using receive we can receive VCard details from server. wodXMPP1.VCard.Receive(); } //VCardDetails Event fires when someone's VCard arrives from the server. void wodXMPP1_VCardDetails(WODXMPPCOMLib.XMPPContact Contact, bool Partial) { System.Drawing.Image im; //Inside VCardDetails Event we can receive new picture from server and load it in PictureBox. im = System.Drawing.Image.FromHbitmap((IntPtr) wodXMPP1.VCard.Photo.Handle); pictureBox1.Image = new System.Drawing.Bitmap(im); }