public static ObexStatusCode SendFile(BluetoothAddress address, string file_path) { Uri uri = new Uri("obex://" + address.ToString() + "/" + file_path); ObexWebResponse response; try { ObexWebRequest request = new ObexWebRequest(uri); request.ReadFile(file_path); response = (ObexWebResponse)request.GetResponse(); response.Close(); } catch (Exception ex) { return ObexStatusCode.InternalServerError; } return response.StatusCode; }
private void btnSendFiles_Click(object sender, EventArgs e) { try { var sbdd = new InTheHand.Windows.Forms.SelectBluetoothDeviceDialog(); sbdd.ShowAuthenticated = true; sbdd.ShowRemembered = true; sbdd.ShowUnknown = true; InTheHand.Net.Sockets.BluetoothDeviceInfo deviceInfo = null; OpenFileDialog openFileDialog = new OpenFileDialog(); if (sbdd.ShowDialog() == DialogResult.OK) { deviceInfo = sbdd.SelectedDevice; if (openFileDialog.ShowDialog() == DialogResult.OK) { var file = openFileDialog.FileName; var uri = new Uri("obex://" + deviceInfo.DeviceAddress + "/" + file); var request = new InTheHand.Net.ObexWebRequest(uri); request.ReadFile(file); var response = (InTheHand.Net.ObexWebResponse)request.GetResponse(); MessageBox.Show(response.StatusCode.ToString()); response.Close(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
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 sendfile() { int index = Selected; InTheHand.Net.BluetoothAddress address = this.address_array[index]; string [] filename = diaglog.FileName.Split('\\'); System.Uri uri = new Uri("obex://" + address.ToString() + "/" + filename[filename.Length -1]); ObexWebRequest request = new ObexWebRequest(uri); if (diaglog.FileName.Trim().Length > 0) { request.ReadFile(diaglog.FileName); ObexWebResponse response = (ObexWebResponse)request.GetResponse(); response.Close(); if (response.StatusCode.ToString().Trim() == "Success, Final") { MessageBox.Show("File Sent"); } } }
public void sendFile(String pathToFile, int index) { bool fileExists = pathToFile != null; bool correctDeviceRange = inRangeIndex(index); if (fileExists && correctDeviceRange) { var file = @pathToFile; var uri = new Uri("obex://" + _devices[index].DeviceAddress + "/" + file); var request = new ObexWebRequest(uri); request.ReadFile(file); var response = (ObexWebResponse) request.GetResponse(); Console.WriteLine(response.StatusCode.ToString()); response.Close(); } else { Console.WriteLine("Złe parametry"); } }
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(); }
/// <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"; } }
private void OnDropBT(object sender, SurfaceDragDropEventArgs e) { var element = e.OriginalSource as FrameworkElement; if (element != null) { if (element.DataContext is BluetoothDevice) { // Target is a Bluetooth device var device = element.DataContext as BluetoothDevice; if (e.Cursor.Data is ContentItem) { var ci = e.Cursor.Data as ContentItem; ObexItem oi = null; if (ci.IsPictureItem) { oi = new ObexImage() { ImageUri = new Uri("pack://application:,,,/" + ci.FileName) }; } else if (ci.IsVisitItem) { oi = new ObexContactItem() { FirstName = ci.Name, LastName = ci.FileName, EmailAddress = ci.Email, MobileTelephoneNumber = ci.Tlf }; } if (oi != null) { // Pause discovery as it interferes with/slows down beam process _monitor.StopDiscovery(); // Create the new request and write the contact details var owr = new ObexWebRequest(new Uri("obex://" + device.DeviceAddress.ToString() + "/" + oi.FileName)); System.IO.Stream s = owr.GetRequestStream(); oi.WriteToStream(s); owr.ContentType = oi.ContentType; owr.ContentLength = s.Length; s.Close(); // Beam the item on new thread System.Threading.ThreadPool.QueueUserWorkItem(BeamObject, owr); } // Return item to the scatter view TargetItems.Add(e.Cursor.Data as ContentItem); var item = scatterViewTarget.Items[scatterViewTarget.Items.Count - 1]; favouriteStack.RemoveInstancePropertyObject(item); } } // Otherwise not supported } }
private void sendnow() { try { System.Uri uri = new Uri("obex://" + sbdd.SelectedDevice.DeviceAddress.ToString() + "/" + System.IO.Path.GetFileName(PlayerEngine.current_track)); request = new ObexWebRequest(uri); request.ReadFile(PlayerEngine.current_track); TrayPopUp("Sending", "The song: " + PlayerEngine.TrackName + " is now being sent to " + sbdd.SelectedDevice.DeviceName, 10); ObexWebResponse response = (ObexWebResponse)request.GetResponse(); // MessageBox.Show(response.StatusCode.ToString()); string buf = response.StatusCode.ToString(); if(buf.Contains("Forbidden")) { TrayPopUp("Unable to send file!", "The file can not be shared because the remote user rejected the request!", 10); } else if(buf.Contains("OK")) { TrayPopUp("Sent!", "The file has been successfully send to " + sbdd.SelectedDevice.DeviceName, 10); } response.Close(); } catch { this.progressBar1.Visible = false; btnBluetoothShare.Image = Properties.Resources.Bluetooth_icon.GetThumbnailImage(16, 16, null, new IntPtr()); TrayPopUp("Error", "Unable to send the file: " + PlayerEngine.TrackName, 10); this.backgroundWorker1.Dispose(); thrSend.Abort(); } btnBluetoothShare.Image = Properties.Resources.Bluetooth_icon.GetThumbnailImage(16, 16, null, new IntPtr()); this.progressBar1.Visible = false; this.backgroundWorker1.Dispose(); try { thrSend.Abort(); } catch { } }
private void OnDrop(object sender, SurfaceDragDropEventArgs e) { FrameworkElement element = e.OriginalSource as FrameworkElement; if (element != null) { ContentItem content = e.Cursor.Data as ContentItem; // ensuring that target is a Bluetooth device and data is ContentItem if (element.DataContext is BluetoothDeviceInfo && content != null) { BluetoothDeviceInfo device = element.DataContext as BluetoothDeviceInfo; // Pause discovery as it interferes with/slows down beam process BlueTimer.Stop(); // Create the new request and write the contact details //ObexWebRequest owr = new ObexWebRequest(new Uri("obex://" + device.DeviceAddress.ToString() + "/" + oi.FileName)); ObexWebRequest owr = new ObexWebRequest(new Uri(String.Format("obex://{0}/{1}", device.DeviceAddress, content.ObexFileName))); using (System.IO.Stream s = owr.GetRequestStream()) { StreamHelper.WriteToStream(s, content); owr.ContentType = content.ObexContentType; owr.ContentLength = s.Length; s.Close(); } // Beam the item on new thread System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(BeamObject), owr); } } }