private void button3_Click(object sender, EventArgs e) { if (textBox2.Text != String.Empty) { string filePath = textBox2.Text; string fileName; BluetoothDeviceInfo device = (BluetoothDeviceInfo)listBox1.SelectedItem; Uri uri = new Uri("obex://" + device.DeviceAddress + "/" + filePath); ObexWebRequest newRequest = new ObexWebRequest(uri); newRequest.ReadFile(filePath); ObexWebResponse response = (ObexWebResponse)newRequest.GetResponse(); response.Close(); MessageBox.Show(response.StatusCode.ToString()); } else { MessageBox.Show("Nie podano sciezki do wysylanego pliku!"); } }
private void btnBeam_Click(object sender, System.EventArgs e) { if (cbDevices.SelectedIndex > -1) { IrDADeviceInfo idi = (IrDADeviceInfo)cbDevices.SelectedItem; if (ofdFileToBeam.ShowDialog() == DialogResult.OK) { Cursor.Current = Cursors.WaitCursor; System.Uri uri = new Uri("obex://" + idi.DeviceAddress.ToString() + "/" + System.IO.Path.GetFileName(ofdFileToBeam.FileName)); ObexWebRequest request = new ObexWebRequest(uri); Stream requestStream = request.GetRequestStream(); FileStream fs = File.OpenRead(ofdFileToBeam.FileName); byte[] buffer = new byte[1024]; int readBytes = 1; while (readBytes != 0) { readBytes = fs.Read(buffer, 0, buffer.Length); requestStream.Write(buffer, 0, readBytes); } requestStream.Close(); ObexWebResponse response = (ObexWebResponse)request.GetResponse(); MessageBox.Show(response.StatusCode.ToString()); response.Close(); Cursor.Current = Cursors.Default; } } }
private void btnBluetooth_Click(object sender, System.EventArgs e) { // use the new select bluetooth device dialog SelectBluetoothDeviceDialog sbdd = new SelectBluetoothDeviceDialog(); sbdd.ShowAuthenticated = true; sbdd.ShowRemembered = true; sbdd.ShowUnknown = true; if (sbdd.ShowDialog() == DialogResult.OK) { if (ofdFileToBeam.ShowDialog() == DialogResult.OK) { Cursor.Current = Cursors.WaitCursor; System.Uri uri = new Uri("obex://" + sbdd.SelectedDevice.DeviceAddress.ToString() + "/" + System.IO.Path.GetFileName(ofdFileToBeam.FileName)); ObexWebRequest request = new ObexWebRequest(uri); request.ReadFile(ofdFileToBeam.FileName); ObexWebResponse response = (ObexWebResponse)request.GetResponse(); MessageBox.Show(response.StatusCode.ToString()); response.Close(); Cursor.Current = Cursors.Default; } } }
private void button1_Click(object sender, EventArgs e) { MessageBox.Show("ObexWebRequest does not support GET."); // // SelectBluetoothDeviceDialog sbdd = new SelectBluetoothDeviceDialog(); sbdd.ShowAuthenticated = true; sbdd.ShowRemembered = true; sbdd.ShowUnknown = true; if (sbdd.ShowDialog() == DialogResult.OK) { Cursor.Current = Cursors.WaitCursor; System.Uri uri = new Uri("obex://" + sbdd.SelectedDevice.DeviceAddress.ToString()); ObexWebRequest request = new ObexWebRequest(uri); request.Method = "GET"; request.ContentType = InTheHand.Net.Mime.MediaTypeNames.ObjectExchange.Capabilities; //request.ReadFile("C:\\t4s.log"); //request.ContentType = InTheHand.Net.Mime.MediaTypeNames.Text.Plain; ObexWebResponse response = (ObexWebResponse)request.GetResponse(); response.Close(); Cursor.Current = Cursors.Default; } }
private void sendFileButton_Click(object sender, EventArgs e) { if (device == null) { MessageBox.Show("Nie wybrano urządzenia!!!"); return; } OpenFileDialog ofd = new OpenFileDialog(); if (ofd.ShowDialog() == DialogResult.OK) { device.Update(); device.Refresh(); device.SetServiceState(BluetoothService.ObexObjectPush, true); var file = ofd.FileName; var uri = new Uri("obex://" + device.DeviceAddress + "/" + file); var request = new ObexWebRequest(uri); request.ReadFile(file); ObexWebResponse response = null; try { response = (ObexWebResponse)request.GetResponse(); MessageBox.Show(response.StatusCode.ToString()); response.Close(); }catch (Exception) { // check response.StatusCode MessageBox.Show("Urządzenie nie odpowiedziło"); } } }
private void Transfer(ObexTransferObject obj) { ObexWebResponse rsp = null; ObexWebRequest req; try { Uri uri = new Uri("obex://" + obj.Target.address.ToString() + "/" + obj.Filename); req = new ObexWebRequest(uri); req.Timeout = 15000; using (Stream content = req.GetRequestStream()) { content.Write(obj.Data, 0, obj.Data.Length); content.Flush(); req.ContentLength = obj.Data.Length; req.ContentType = obj.MimeType; } rsp = (req.GetResponse() as ObexWebResponse); } catch (Exception e) { General.WriteLogLine(e.GetType().Name + " while transferring '" + obj.Filename + "' data to " + obj.Target.address.ToString() + ": " + e.Message); } if ((rsp != null) && (rsp.StatusCode != ObexStatusCode.OK)) { General.WriteLogLine("Received response code: " + rsp.StatusCode + " while transferring '" + obj.Filename + "' data to " + obj.Target.address.ToString()); } if (rsp != null) { rsp.Close(); } }
private void button4_Click(object sender, EventArgs e) { SelectBluetoothDeviceDialog dialog = new SelectBluetoothDeviceDialog(); // dialog.ShowAuthenticated = true; dialog.ShowRemembered = true; dialog.ShowUnknown = true; OpenFileDialog ofd = new OpenFileDialog(); if (ofd.ShowDialog() == DialogResult.OK) { System.Uri uri = new Uri("obex://" + selectedDevice.DeviceInfo.DeviceAddress + "/" + 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"); } }
private void pushObexFileToBeam() { // use the new select bluetooth device dialog SelectBluetoothDeviceDialog mSelectBluetoothDeviceDialog = new SelectBluetoothDeviceDialog(); mSelectBluetoothDeviceDialog.ShowAuthenticated = true; // 顯示已經記住的藍牙設備 mSelectBluetoothDeviceDialog.ShowRemembered = true; // 顯示認證過的藍牙設備 mSelectBluetoothDeviceDialog.ShowUnknown = true; // 顯示位置藍牙設備 if (mSelectBluetoothDeviceDialog.ShowDialog() == DialogResult.OK) { OpenFileDialog ofdFileToBeam = new OpenFileDialog(); // 選擇要傳送文件的目的地後, 通過OpenFileDialog選擇要傳輸的文件 ofdFileToBeam.Filter = "Only Text File (*.txt)|*.txt"; // ofdFileToBeam.Filter = "All Files (*.*)|*.*"; if (ofdFileToBeam.ShowDialog() == DialogResult.OK) { Cursor.Current = Cursors.WaitCursor; System.Uri uri = new Uri("obex:// " + mSelectBluetoothDeviceDialog.SelectedDevice.DeviceAddress.ToString() + "/" + System.IO.Path.GetFileName(ofdFileToBeam.FileName)); ObexWebResponse response = null; try { // ObexWebRequest 的實現模式和HttpWebRequest類似, 都是發送請求, 等等回應, 回應封裝在ObexWebResponse 類裡面. ObexWebRequest request = new ObexWebRequest(uri); // 通過ObexWebRequest 來傳送文件到目標機器 request.ReadFile(ofdFileToBeam.FileName); response = request.GetResponse() as ObexWebResponse; txtCompareFileResult.ForeColor = Color.Green; txtCompareFileResult.Text = "PASS"; if (IsDebugMode) { Trace.WriteLine("File transfer was successful."); } checkTestStatus("PASS"); } catch (Exception ex) { txtCompareFileResult.ForeColor = Color.Red; txtCompareFileResult.Text = "FAIL"; if (IsDebugMode) { Trace.WriteLine("File transfer failed. Path : " + uri); } checkTestStatus(ex.Message); } finally { if (response != null) { response.Close(); } } Cursor.Current = Cursors.Default; } } }
public void SendTempFile(string fileName) { string filePath = fileName; var uri = new Uri("obex://" + choosenDevice.DeviceAddress + "/" + filePath); ObexWebRequest request = new ObexWebRequest(uri); request.ReadFile(filePath); ObexWebResponse response = (ObexWebResponse)request.GetResponse(); response.Close(); }
private static ObexStatusCode SendFile(BluetoothAddress adr, string path) { Uri uri = new Uri("obex://" + adr.ToString() + "/" + path); ObexWebRequest req = new ObexWebRequest(uri); req.ReadFile(path); ObexWebResponse response = (ObexWebResponse)req.GetResponse(); response.Close(); return(response.StatusCode); }
void Obex1() { BluetoothAddress addr = BluetoothAddress.Parse("002233445566"); String path = "HelloWorld.txt"; // var req = new ObexWebRequest(addr, path); req.ReadFile("Hello World.txt"); ObexWebResponse rsp = (ObexWebResponse)req.GetResponse(); Console.WriteLine("Response Code: {0} (0x{0:X})", rsp.StatusCode); }
public void sendTempFile() { Console.WriteLine("Staring sending file"); string filePath = "../cat.jpg"; var uri = new Uri("obex://" + choosenDevice.DeviceAddress + "/" + filePath); ObexWebRequest request = new ObexWebRequest(uri); request.ReadFile(filePath); ObexWebResponse response = (ObexWebResponse)request.GetResponse(); response.Close(); Console.WriteLine("End of sending file"); }
private void sendfile() { int index = selected; InTheHand.Net.BluetoothAddress address = devices[index].DeviceAddress; System.Uri uri = new Uri("obex://" + address.ToString() + "/" + "sample.txt"); //Change it to your file name ObexWebRequest request = new ObexWebRequest(uri); request.ReadFile("c:\\users\\chinmay\\sample.txt"); // Chnage it to your File Path ObexWebResponse response = (ObexWebResponse)request.GetResponse(); response.Close(); }
public static ObexStatusCode SendFile(BluetoothAddress address, string file_path) { string FileName = file_path.Substring(file_path.LastIndexOf("\\")); Uri uri = new Uri("obex://" + address.ToString() + "/" + file_path); ObexWebRequest request = new ObexWebRequest(uri); request.ReadFile(file_path); ObexWebResponse response = (ObexWebResponse)request.GetResponse(); response.Close(); return(response.StatusCode); }
private void bSend_Click(object sender, EventArgs e) { OpenFileDialog fileDialog = new OpenFileDialog(); if (fileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string sciezka = fileDialog.FileName.Substring(fileDialog.FileName.LastIndexOf("\\")); Uri uri = new Uri("obex://" + adres.ToString() + "/" + sciezka); ObexWebRequest request = new ObexWebRequest(uri); request.ReadFile(fileDialog.FileName); ObexWebResponse response = (ObexWebResponse)request.GetResponse(); response.Close(); } }
private void sendfile() { var filepath = FileDialogue(); foreach (var x in filepath) { string filename = Path.GetFileName(x); int index = Selected; InTheHand.Net.BluetoothAddress address = this.address_array[index]; System.Uri uri = new Uri("obex://" + address.ToString() + "/" + filename); ObexWebRequest request = new ObexWebRequest(uri); request.ReadFile(x); ObexWebResponse response = (ObexWebResponse)request.GetResponse(); response.Close(); } }
public void sendFile() { OpenFileDialog dialog = new OpenFileDialog(); if (dialog.ShowDialog() == DialogResult.OK) { if (chosenDevice != null && chosenRadio != null) { var uri = new Uri("obex://" + chosenDevice.DeviceAddress + "/" + dialog.FileName); ObexWebRequest request = new ObexWebRequest(uri); request.ReadFile(dialog.FileName); ObexWebResponse response = (ObexWebResponse)request.GetResponse(); response.Close(); } } }
public static ObexStatusCode sendFile(BluetoothDeviceInfo device, string fileToSend) { String fileName = fileToSend.Substring(fileToSend.LastIndexOf("\\")); System.Console.WriteLine($"File name: {fileName}"); // Build te OBEX uri and create an OBEX web request var obexUri = new Uri("obex://" + device.DeviceAddress + "/" + fileToSend); var request = new ObexWebRequest(obexUri); // Fill the request with the file data request.ReadFile(fileToSend); // Send the request to the targeted bluetooth device ObexWebResponse response = request.GetResponse() as ObexWebResponse; response.Close(); return(response.StatusCode); }
private void SendFileButton_Click(object sender, RoutedEventArgs e) { OpenFileDialog fileChoice = new OpenFileDialog(); fileChoice.RestoreDirectory = true; if (fileChoice.ShowDialog() == true) { string fileName = fileChoice.FileName; ObexWebRequest request = new ObexWebRequest( new Uri("obex://" + device.DeviceAddress + "/" + fileName) ); request.ReadFile(fileName); ObexWebResponse response = (ObexWebResponse)request.GetResponse(); response.Close(); MessageBox.Show("Result message:\n" + response.StatusCode.ToString()); } else { MessageBox.Show("You didn't choose a file"); } }
private void SendFiles(object o) { foreach (string fileName in listBox3.Items) { try { SynchronizationContext cntx = o as SynchronizationContext; cntx.Send(UpdateStartSendingMess, fileName); Uri uri = new Uri("obex://" + chosenDevice.DeviceAddress.ToString() + "/" + fileName); ObexWebRequest request = new ObexWebRequest(uri); request.ReadFile(fileName); ObexWebResponse response = (ObexWebResponse)request.GetResponse(); cntx.Send(UpdateCorrectSendingMess, response.StatusCode); } catch (Exception error) { SynchronizationContext cntxerr = o as SynchronizationContext; String mess = error.Message; cntxerr.Send(UpdateErrorSendingMess, mess); } } }
/// <summary> /// Send a file to an attached external bluetooth device. /// You must first Initialise, then set the device. /// </summary> /// <param name="fileName">The file to send.</param> /// <returns>A result status message "True" or "False".</returns> public static Primitive SendFile(Primitive fileName) { if (!System.IO.File.Exists(fileName)) { Utilities.OnFileError(Utilities.GetCurrentMethod(), fileName); return("False"); } BluetoothDeviceInfo info = GetBluetoothDeviceInfo(device); if (null == info) { lastError = "Device not set"; return("False"); } try { Uri uri = new Uri("obex://" + info.DeviceAddress.ToString() + "/" + System.IO.Path.GetFileName(fileName)); ObexWebRequest request = new ObexWebRequest(uri); request.ReadFile(fileName); ObexWebResponse response = (ObexWebResponse)request.GetResponse(); if (response.StatusCode.ToString().Contains("OK")) { return("True"); } else { lastError = response.StatusCode.ToString(); return("False"); } } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); lastError = ex.Message; return("False"); } }
public static ObexStatusCode SendFile(BluetoothAddress address, string file_path) { var obexUri = new Uri("obex://" + address + "/" + file_path); ObexWebRequest request = new ObexWebRequest(obexUri); ObexWebResponse response = null; request.ReadFile(file_path); try { response = (ObexWebResponse)request.GetResponse(); response.Close(); MessageBox.Show("Plik wysłany \n Kod odpowiedzi: " + response.StatusCode.ToString()); return(response.StatusCode); } catch (Exception e) { MessageBox.Show("Nie udało się wysłać pliku:\n" + e.Message + " " + e.ToString()); } return(response.StatusCode); }
/// <summary> /// Sends a file to the selected device /// </summary> /// <param name="filePath">The full local file path</param> /// <param name="receiverName">The name of the receiving device</param> public void SendFile(string filePath, string receiverName) { // We enumerate all the devices in the list foreach (var device in DevicesInfo[0]) { // If the selected device from the list has the same name as the current device being scanned, we have found the right device if (device.DeviceName == receiverName) { // If the sender device and the receiver device aren't paired if (!device.Authenticated) { // We request the pairing process with a random PIN if (!BluetoothSecurity.PairRequest(device.DeviceAddress, null)) { // This will happen when the pairing process goes bad MessageBox.Show("Unable to connect!", "Pair Request"); goto resetSendFileButton; } } try { // We create our request using a Uri string which contains the receiving device address and the local file path ObexWebRequest obexWebRequest = new ObexWebRequest((new Uri(String.Format("obex://{0}/{1}", device.DeviceAddress, filePath)))); // Reads the entire file into memory (if you have a file bigger than 1.5 GB you will get an Out Of Memory exception) obexWebRequest.ReadFile(filePath); // When the file was read, we make the request and the receiving device will send back a response ObexWebResponse obexWebResponse = (ObexWebResponse)obexWebRequest.GetResponse(); obexWebResponse.Close(); // If the response is 'OK' and is the final response, the file was successfully sent if (obexWebResponse.StatusCode == (ObexStatusCode.OK | ObexStatusCode.Final)) { MessageBox.Show("File successfully sent!"); } // Otherwise, if the receiving device reject our sending request, we show it to the user else if (obexWebResponse.StatusCode == (ObexStatusCode.Forbidden | ObexStatusCode.Final)) { MessageBox.Show("The other device rejected the request!"); } } catch (Exception _e) { // If something bad happens during the process and the user has not aborted the operation // We show the exception error if (!AbortOperation) { MessageBox.Show(String.Format("Message Error: {0}", _e.Message), "Something bad has happened"); } else { // If the operation was aborted by the user, we need to set back to 'false' the 'AbortOperation' value for further operations AbortOperation = false; } } break; } } // Used only to reset the text for the 'Send File' button resetSendFileButton: Frm.sendCancelFile_btn.Invoke((MethodInvoker) delegate { Frm.sendCancelFile_btn.Text = "Send File"; }); }
private void button3_Click(object sender, EventArgs e) { SelectBluetoothDeviceDialog dialog = new SelectBluetoothDeviceDialog(); // dialog.ShowAuthenticated = true; dialog.ShowRemembered = true; dialog.ShowUnknown = true; OpenFileDialog ofd = new OpenFileDialog(); if (ofd.ShowDialog() == DialogResult.OK) { System.Uri uri = new Uri("obex://" + selectedDevice.DeviceInfo.DeviceAddress + "/" + 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"); } /* * string FileName = textBox2.Text; * * SelectBluetoothDeviceDialog dialog = new SelectBluetoothDeviceDialog(); * * // dialog.ShowAuthenticated = true; * * dialog.ShowRemembered = true; * * dialog.ShowUnknown = true; * * OpenFileDialog ofd = new OpenFileDialog(); * * System.Uri uri = new Uri("obex://" + selectedDevice.DeviceInfo.DeviceAddress + "/" + FileName); * * ObexWebRequest request = new ObexWebRequest(uri); * * request.ReadFile(FileName); * * * ObexWebResponse response = (ObexWebResponse)request.GetResponse(); * * MessageBox.Show(response.StatusCode.ToString()); * * response.Close(); * * Cursor.Current = Cursors.Default; * * * * * /* * * string tmpWiadomosc = textBox2.Text; * * if (selectedDevice == null) * { * MessageBox.Show("Nie znaleziono urządzenia !"); * } * else * if (string.IsNullOrEmpty(tmpWiadomosc)) * { * MessageBox.Show("Nie wprowadzono tekstu !"); * } * else * { * Guid _serviceClassId = new Guid("9bde4762-89a6-418e-bacf-fcd82f1e0677"); * //Guid _serviceClassId = new Guid("00000000-0000-1000-8000-00805F9B34FB"); * //Guid _serviceClassId = ; * * * * var bluetoothClient = new BluetoothClient(); * var ep = new BluetoothEndPoint(selectedDevice.DeviceInfo.DeviceAddress, _serviceClassId); * * * * // connecting * bluetoothClient.Connect(ep); * * * * // get stream for send the data * var bluetoothStream = bluetoothClient.GetStream(); * * // if all is ok to send * if (bluetoothClient.Connected && bluetoothStream != null) * { * // write the data in the stream * var buffer = System.Text.Encoding.UTF8.GetBytes(tmpWiadomosc); * bluetoothStream.Write(buffer, 0, buffer.Length); * bluetoothStream.Flush(); * bluetoothStream.Close(); * * } * else * MessageBox.Show("Wystąpił problem z połączeniem..."); * * * * } */ }