using InTheHand.Net; using InTheHand.Net.Sockets; using InTheHand.Net.Bluetooth; using InTheHand.Windows.Forms; using InTheHand.Net.Ports; using System.Threading; namespace Bluetooth { public partial class Form1 : Form { public Form1() { InitializeComponent(); } InTheHand.Net.BluetoothAddress[] address_array = new BluetoothAddress[1000]; private Thread thrSend; private void Form1_Load(object sender, EventArgs e) { } private void label1_Click(object sender, EventArgs e) { } private void label3_Click(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { InTheHand.Net.Sockets.BluetoothClient bc = new InTheHand.Net.Sockets.BluetoothClient(); InTheHand.Net.Sockets.BluetoothDeviceInfo[] array = bc.DiscoverDevices(); for (int i = 0; i < array.Length; i++) { this.address_array[i] = array[i].DeviceAddress; this.lstDevices.Items.Add(array[i].DeviceName); } } private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { } private void button2_Click(object sender, EventArgs e) { if (this.lstDevices.SelectedIndex == -1) { MessageBox.Show("Please select a device."); return; } int index = this.lstDevices.SelectedIndex; string mac = this.address_array[index].ToString(); string nap = this.address_array[index].Nap.ToString(); string sap = this.address_array[index].Sap.ToString(); MAC.Text = "MAC : " + mac.ToString(); NAP.Text = "NAP :" + nap.ToString(); SAP.Text = "SAP :" + sap.ToString(); } private void button3_Click(object sender, EventArgs e) { this.thrSend = new Thread(new ThreadStart(sendfile)); this.thrSend.Start(); } private void sendfile() { SelectBluetoothDeviceDialog dialog = new SelectBluetoothDeviceDialog(); dialog.ShowAuthenticated = true; dialog.ShowRemembered = true; dialog.ShowUnknown = true; OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "Select File"; ofd.Filter = "All Files (*.*)|.*"; if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (ofd.ShowDialog() == DialogResult.OK) { Cursor.Current = Cursors.WaitCursor; System.Uri uri = new Uri("obex://" + dialog.SelectedDevice.ToString() + "/" + ofd.FileName); ObexWebRequest request = new ObexWebRequest(uri); request.ReadFile(ofd.FileName); ObexWebResponse response = (ObexWebResponse)request.GetResponse(); MessageBox.Show(response.StatusCode.ToString()); response.Close(); Cursor.Current = Cursors.Default; } else { MessageBox.Show("File Not Selected"); } } else { MessageBox.Show("Device Not Selected"); } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)