public void reciveFile()
 {
     var listener = new ObexListener(ObexTransport.Bluetooth);
     listener.Start();
     ObexListenerContext context = listener.GetContext();
     ObexListenerRequest request = context.Request;
     String[] pathSplits = request.RawUrl.Split('/');
     String filename = pathSplits[pathSplits.Length - 1];
     request.WriteFile(filename);
     listener.Stop();
     Console.WriteLine("Odebrano plik!");
 }
        private void btnReceiveFiles_Click_Click(object sender, EventArgs e)
        {
            try
            {
                InTheHand.Net.ObexListener listener = new InTheHand.Net.ObexListener();
                listener.Start();

                InTheHand.Net.ObexListenerContext      context = null;
                BluetoothRijndael.frmWaitingConnection waitingConnectionForm = new BluetoothRijndael.frmWaitingConnection();
                FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();

                new Thread(() =>
                {
                    Thread.CurrentThread.IsBackground = true;
                    context = listener.GetContext();
                    if (waitingConnectionForm.Visible)
                    {
                        waitingConnectionForm.Invoke(new MethodInvoker(delegate { waitingConnectionForm.Close(); }));
                    }
                }).Start();

                if (waitingConnectionForm.ShowDialog() == DialogResult.Cancel)
                {
                    if (listener.IsListening)
                    {
                        listener.Stop();
                    }
                }

                if (context != null)
                {
                    if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
                    {
                        string fileLocation = folderBrowserDialog.SelectedPath + context.Request.RawUrl;
                        context.Request.WriteFile(fileLocation);
                        MessageBox.Show("File saved at: \n" + fileLocation);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #3
0
 /// <summary>
 /// Receive (fetch) a file from an attached external bluetooth device.
 /// You must first Initialise, then set the device.
 /// </summary>
 /// <param name="fileName">The location to save the received file.</param>
 /// <returns>A result status message "True" or "False".</returns>
 public static Primitive ReceiveFile(Primitive fileName)
 {
     BluetoothDeviceInfo info = GetBluetoothDeviceInfo(device);
     if (null == info || null == bluetoothClient)
     {
         lastError = "Device or client not set";
         return "False";
     }
     try
     {
         ObexListener ol = new ObexListener(ObexTransport.Bluetooth);
         ol.Start();
         while (ol.IsListening)
         {
             try
             {
                 ObexListenerContext olc = ol.GetContext();
                 ObexListenerRequest olr = olc.Request;
                 olr.WriteFile(fileName);
                 ol.Stop();
             }
             catch (Exception ex)
             {
                 Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                 lastError = ex.Message;
                 return "False";
             }
         }
         return "True";
     }
     catch (Exception ex)
     {
         Utilities.OnError(Utilities.GetCurrentMethod(), ex);
         lastError = ex.Message;
         return "False";
     }
 }