Click here to Skip to main content
15,901,205 members
Home / Discussions / C#
   

C#

 
QuestionHow to print Datagrid in C# 2005 ? Pin
hdv2127-Oct-06 7:37
hdv2127-Oct-06 7:37 
AnswerRe: How to print Datagrid in C# 2005 ? Pin
Nader Elshehabi8-Oct-06 6:47
Nader Elshehabi8-Oct-06 6:47 
Questioncommand line usage of csc Pin
waheed awan7-Oct-06 7:16
waheed awan7-Oct-06 7:16 
AnswerRe: command line usage of csc Pin
Daniel Monzert7-Oct-06 21:20
Daniel Monzert7-Oct-06 21:20 
QuestionHelp - Send a File via Socket Pin
FlyOnIT7-Oct-06 5:49
FlyOnIT7-Oct-06 5:49 
AnswerRe: Help - Send a File via Socket Pin
Andrei Ungureanu7-Oct-06 7:34
Andrei Ungureanu7-Oct-06 7:34 
GeneralRe: Help - Send a File via Socket Pin
FlyOnIT7-Oct-06 8:31
FlyOnIT7-Oct-06 8:31 
GeneralRe: Help - Send a File via Socket Pin
Andrei Ungureanu7-Oct-06 8:51
Andrei Ungureanu7-Oct-06 8:51 
You can create your own communication protocol. Let's say that the client sends a message to the server telling him that he will upload a file with a specified extension and size. The server sends back an acknowledge message and the the client sends the file.
Concerning the server. If you know the exact size of the file then you can do something like:
byte[] buffer = new byte[size];
client.Receive(buffer);

If you do not know the size of the file then you can write a sequence that reads data from the network in packets let's say 1024 long, like this:
ArrayList list = new ArrayList();
byte[] buffer = new byte[1024];
int read = 0;
int length = 0;
while ((read = client.Receive(buffer) != 0)
{
 length += read;
 list.Add(buffer);
 buffer = new byte[1024];
 if (read < 1024) // reached the end of file
  break;
}

At the end of this code you have inside the array list the entire file stored in 1024 length byte , arrays. After this just extract the byte arrays from the array list, like this.
buffer = new byte[length];
byte []temp = null;
int k = 0;
for (int i = 0 ; i < list.Count ; i++)
{
 temp = (byte[])list[i];
 for (int j = 0 ; j < temp.Length ; j++)
    byte[k++] = temp[j];
}

Hope it helps.

Do your best to be the best

GeneralRe: Help - Send a File via Socket Pin
FlyOnIT7-Oct-06 10:09
FlyOnIT7-Oct-06 10:09 
GeneralRe: Help - Send a File via Socket Pin
FlyOnIT8-Oct-06 1:14
FlyOnIT8-Oct-06 1:14 
GeneralRe: Help - Send a File via Socket Pin
FlyOnIT8-Oct-06 8:52
FlyOnIT8-Oct-06 8:52 
Questionmicrosoft agent Pin
Mohammed Elkholy7-Oct-06 5:19
Mohammed Elkholy7-Oct-06 5:19 
QuestionHow do I submit a book review? Pin
Wolf927-Oct-06 5:12
Wolf927-Oct-06 5:12 
QuestionHelp Parsing HTML/String Pin
UFGrayMatter7-Oct-06 4:02
UFGrayMatter7-Oct-06 4:02 
AnswerRe: Help Parsing HTML/String Pin
Guffa7-Oct-06 11:49
Guffa7-Oct-06 11:49 
GeneralRe: Help Parsing HTML/String Pin
UFGrayMatter7-Oct-06 11:57
UFGrayMatter7-Oct-06 11:57 
AnswerRe: Help Parsing HTML/String Pin
Guffa7-Oct-06 12:16
Guffa7-Oct-06 12:16 
QuestionInheriting from the tabcontrol Pin
thepersonof7-Oct-06 3:01
thepersonof7-Oct-06 3:01 
AnswerRe: Inheriting from the tabcontrol Pin
Captain See Sharp7-Oct-06 4:12
Captain See Sharp7-Oct-06 4:12 
GeneralRe: Inheriting from the tabcontrol Pin
thepersonof13-Oct-06 10:48
thepersonof13-Oct-06 10:48 
QuestionFiles in folder Pin
Mohammed Elkholy7-Oct-06 2:48
Mohammed Elkholy7-Oct-06 2:48 
AnswerRe: Files in folder Pin
DownBySpj7-Oct-06 3:06
DownBySpj7-Oct-06 3:06 
QuestionRaising events in C# Pin
Mahhouraaaaaa7-Oct-06 1:44
Mahhouraaaaaa7-Oct-06 1:44 
AnswerRe: Raising events in C# Pin
Captain See Sharp7-Oct-06 4:02
Captain See Sharp7-Oct-06 4:02 
QuestionGet time Pin
mehrdadc487-Oct-06 1:39
mehrdadc487-Oct-06 1:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.