bluetooth file send

吃可爱长大的小学妹 提交于 2019-12-05 22:00:35
cheesebunz

ans:

string fileName = @"SendTest.txt";

String adr = "0025677FB346";
Uri uri = new Uri("obex://" + adr + "/" + System.IO.Path.GetFileName(fileName)); 
ObexWebRequest request = new ObexWebRequest(uri);
request.ReadFile(fileName);

ObexWebResponse response = (ObexWebResponse)request.GetResponse();
MessageBox.Show(response.StatusCode.ToString());
response.Close();

The C4F (Coding 4 Fun Kit) has an implementation of obex - http://blogs.msdn.com/b/coding4fun/archive/2007/08/02/4192571.aspx

I've used it and found it to be quite reliable.

pjb
// The host part of the URI is the device address, e.g. IrDAAddress.ToString(),
// and the file part is the OBEX object name.

{
    string addr = "112233445566";
    Uri uri = new Uri("obex://" + addr + "/HelloWorld2.txt");
    ObexWebRequest req = new ObexWebRequest(uri);
    using (Stream content = req.GetRequestStream()) {
        // Using a StreamWriter to write text to the stream...
        using (StreamWriter wtr = new StreamWriter(content)) {
            wtr.WriteLine("Hello World GetRequestStream");
            wtr.WriteLine("Hello World GetRequestStream 2");
            wtr.Flush();
            // Set the Length header value
            req.ContentLength = content.Length;
        }
    }
    // In this case closing the StreamWriter also closed the Stream, but ...
    ObexWebResponse rsp = (ObexWebResponse)req.GetResponse();
    Console.WriteLine("Response Code: {0} (0x{0:X})", rsp.StatusCode);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!