Я использую 32feet. NET и я написал этот код:
но у него есть некоторые проблемы. если рекомендован другой способ, пожалуйста, сообщите мне. в остальном, пожалуйста, помогите мне решить текущие проблемы.
- Когда я читал потоковые байты для записи в файл, потребовалось так много времени. и после записи в файл были записаны неверные данные

- как мне получить расширение принимающего файла?
{
InitializeComponent();
_bluetoothListener = new BluetoothListener(BluetoothService.ObexObjectPush);
_listenerThread = new Thread(ListenForBluetoothRequests);
_listenerThread.Start();
}
private void ListenForBluetoothRequests()
{
_bluetoothListener.Start();
while (true)
{
try
{
_bluetoothListener.Pending();
BluetoothClient client = _bluetoothListener.AcceptBluetoothClient();
if (client != null)
{
// Handle the incoming file transfer
HandleIncomingFile(client);
// Close the client connection
client.Close();
}
}
catch (IOException ex)
{
// Handle exceptions, if any
Console.WriteLine("Exception: " + ex.Message);
}
}
}
private void HandleIncomingFile(BluetoothClient client)
{
// Customize the file save path as per your requirement
string savePath = "C:\\BluetoothReceivedFiles\\";
if (!Directory.Exists(savePath))
{
Directory.CreateDirectory(savePath);
}
Stream networkStream = client.GetStream();
byte[] buffer = new byte[1024];
int bytesRead;
// Read the incoming file and save it
using (FileStream fileStream = File.Create(Path.Combine(savePath, "ReceivedFile.txt")))
{
while ((bytesRead = networkStream.Read(buffer, 0, buffer.Length)) > 0)
{
fileStream.Write(buffer, 0, bytesRead);
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/779 ... in-c-sharp
Мобильная версия