IT Community - Software Programming, Web Development and Technical Support

How to send a file from a pocket pc to another pocket pc using C#.Net?

This is a discussion on How to send a file from a pocket pc to another pocket pc using C#.Net? within the Mobile Software Development forums, part of the Software Development category; How to send a file from a pocket pc to another pocket pc using C#.Net? I am using windows ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > Mobile Software Development

Register FAQ Members List Calendar Mark Forums Read
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 07-17-2007, 03:51 AM
mobilegeek mobilegeek is offline
D-Web Analyst
 
Join Date: Jun 2007
Posts: 205
mobilegeek is on a distinguished road
Default How to send a file from a pocket pc to another pocket pc using C#.Net?

How to send a file from a pocket pc to another pocket pc using C#.Net?

I am using windows mobile 5.0 in dot net. I need to send a file from one pocket pc to another pocket pc via Bluetooth using c#.

Is there any sample for sending file using C#.Net?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-07-2007, 01:45 AM
krishnakumar krishnakumar is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 206
krishnakumar is on a distinguished road
Default Re: How to send a file from a pocket pc to another pocket pc using C#.Net?

Hi,
i hope that u know the discovering the bluetooth enabled devices and connect with that selected devices... u dont know the method of file sendings..
This following code will explain the file sending concept.. For file sending we shall use third party tool called InTheHand... U can download the InTheHand Software and install it...
After that u can add that dll in ur reference..... Lets go through the following code after connecting the devices with ur device.. For example the file, u have to send is "sample.txt" which is in "C:\samplefolder\sample.txt"....



string fName = Path.GetFileName(@"C://samplefolder//sample.txt");
string fType = "";
StreamReader sr = File.OpenText(fileName);
string fFileContent = sr.ReadToEnd();
sr.Close();

//send client request, start put
int result = OBEXRequest("PUT",fName,fType, fFileContent);

switch (result)
{
case 160: // 0xa0
MessageBox.Show("File Send");
break;

case 197: // 0xc5
MessageBox.Show("Method not allowed");
break;

case 192: // 0xc0
MessageBox.Show("Bad Request");
break;

default:
MessageBox.Show("Other Error");
break;
}
}

else
{
MessageBox.Show("Failed to connect to OBEX Server");
}
}

private int OBEXRequest(string tReqType,string tName,string tType, string tFileContent)
{
int i;
int offset;
int packetsize;
byte reqtype = 0x82;

int tTypeLen = 0x03;
int typeheadsize;
int typesizeHi = 0x00;
int typesizeLo = 0x03;

if (tReqType == "GET")
{
reqtype = 0x83; // 131 GET-Final
}

if (tReqType == "PUT")
{
reqtype = 0x82; // 130 PUT-Final
}

packetsize = 3;

//Name Header
int tNameLength = tName.Length;
int nameheadsize = (3 + (tNameLength * 2) + 2);
int namesizeHi = (nameheadsize & 0xff00) / 0xff;
int namesizeLo = nameheadsize & 0x00ff;
packetsize = packetsize + nameheadsize;

if (tType != "")
{
//Type Header
tTypeLen = tType.Length;
typeheadsize = 3 + tTypeLen + 1;
typesizeHi = (typeheadsize & 0xff00) / 0xff;
typesizeLo = typeheadsize & 0x00ff;
packetsize = packetsize + typeheadsize;
}

//Body
int fileLen = tFileContent.Length;
int fileheadsize = 3 + fileLen;
int filesizeHi = (fileheadsize & 0xff00) / 0xff; ;
int filesizeLo = fileheadsize & 0x00ff; ;

packetsize = packetsize + fileheadsize;

int packetsizeHi = (packetsize & 0xff00) / 0xff;
int packetsizeLo = packetsize & 0x00ff;

byte[] tSendByte = new byte[packetsize];

//PUT-final Header
tSendByte[0] = reqtype; // Request type e.g. PUT-final 130
tSendByte[1] = Convert.ToByte(packetsizeHi); // Packetlength Hi
tSendByte[2] = Convert.ToByte(packetsizeLo); // Packetlength Lo

offset = 2;

//Name Header
tSendByte[offset + 1] = 0x01; // HI for Name header
tSendByte[offset + 2] = Convert.ToByte(namesizeHi); // Length of Name header (2 bytes per char)
tSendByte[offset + 3] = Convert.ToByte(namesizeLo); // Length of Name header (2 bytes per char)

// Name+\n\n in unicode
byte[] tNameU = System.Text.Encoding.BigEndianUnicode.GetBytes(tNa me);
tNameU.CopyTo(tSendByte, offset + 4);

offset = offset + 3 + (tNameLength * 2);
tSendByte[offset + 1] = 0x00; // null term
tSendByte[offset + 2] = 0x00; // null term

offset = offset + 2;

if (tType != "")
{
//Type Header
tSendByte[offset + 1] = 0x42; // HI for Type Header 66
tSendByte[offset + 2] = Convert.ToByte(typesizeHi); // Length of Type Header
tSendByte[offset + 3] = Convert.ToByte(typesizeLo); // Length of Type Header

for (i = 0; i <= (tTypeLen - 1); i++)
{
tSendByte[offset + 4 + i] = Convert.ToByte(Convert.ToChar(tType.Substring(i, 1)));
}
tSendByte[offset + 3 + tTypeLen + 1] = 0x00; // null terminator

offset = offset + 3 + tTypeLen + 1;
}

//Body
tSendByte[offset + 1] = 0x49; //HI End of Body 73
tSendByte[offset + 2] = Convert.ToByte(filesizeHi); //
tSendByte[offset + 3] = Convert.ToByte(filesizeLo); //1k payload + 3 for HI header

for (i = 0; i <= (fileLen - 1); i++)
{
tSendByte[offset + 4 + i] = Convert.ToByte(Convert.ToChar(tFileContent.Substri ng(i, 1)));
}
//tSendByte[offset+4+fileLen] = 0x00; // null terminator

offset = offset + 3 + fileLen;

stream.Write(tSendByte, 0, tSendByte.Length);

//listen for server response

//TODO: can hang here forever waiting response...

bool x = stream.DataAvailable; // changed bluetoothclient - public NetworkStream GetStream()

byte[] tArray4 = new byte[3];
stream.Read(tArray4, 0, 3);

x = stream.DataAvailable;

if (tArray4[0] == 160) // 0xa0
{
int plength = (tArray4[1] * 256) + tArray4[2] - 3;
byte[] tArray5 = new byte[plength];
if (plength > 0)
{
stream.Read(tArray5, 0, plength);
//TODO: data in returned packet to deal with
}
return 160;
}

if (tArray4[0] == 197) // 0xc5 Method not allowed
{
return 197;
}

if (tArray4[0] == 192) // 0xc0 Bad Request
{
return 192;
}

return 0;
}
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-31-2007, 06:59 AM
krishnakumar krishnakumar is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 206
krishnakumar is on a distinguished road
Thumbs up Re: How to send a file from a pocket pc to another pocket pc using C#.Net?

Hi,
I have send a file which has the size of 100kb from PocketPc to PocketPc Via bluetooth.. If i send a file having the size more than 100kb, that file cant reach to the another pocketpc fully....
Can anyone help me to send a file have the size more than 100kb....
__________________
Krishnakumar.S
Beware of Everything -that is un true; stick to the Truth shall succeed slowly but steadily
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 08-31-2007, 07:44 AM
amansundar amansundar is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 325
amansundar is on a distinguished road
Default Re: How to send a file from a pocket pc to another pocket pc using C#.Net?

hi krishna,
Me too had this type of problem when i browse some image files and trying to send those file from one mobile to another via bluetooth...so better option is try sending those files as chuck...which may help u ..and plz let me to know the
response.....
__________________
cheers
Aman

Last edited by amansundar : 08-31-2007 at 07:50 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 09-01-2007, 05:15 AM
krishnakumar krishnakumar is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 206
krishnakumar is on a distinguished road
Smile Re: How to send a file from a pocket pc to another pocket pc using C#.Net?

Hi aman,
I have another doubt.. Like Bluetooth facilities, we have WI-FI Facilities in mobile... I need to enable Wi-Fi services programmatically in windowsmobile using C#...Is it possible to enable this functionality....If u came to know, just share it here......
__________________
Krishnakumar.S
Beware of Everything -that is un true; stick to the Truth shall succeed slowly but steadily
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/mobile-software-development/1955-how-send-file-pocket-pc-another-pocket-pc-using-c-net.html
Posted By For Type Date
mixcat: Blogs, Photos, Videos and more on Technorati This thread Refback 07-20-2007 10:03 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
Do we have facilities to send SMS thru asp? kingmaker Other Web Programming Languages 3 07-17-2008 11:58 AM
Can we move an image programmatically in pocket pc without flickering using C#? mobilegeek Mobile Software Development 3 04-23-2008 09:17 PM
How to Send mail using dot net ...? a.deeban ASP and ASP.NET Programming 9 01-17-2008 09:20 PM
File extension of the code file & object repository file in QTP vigneshgets Testing Tools 1 01-16-2008 11:43 PM
send the sms using SMS/MMS Gateway in php varghese PHP Programming 1 09-18-2007 08:32 AM


All times are GMT -7. The time now is 10:02 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0