471,306 Members | 1,215 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,306 software developers and data experts.

sending empty files

Hi
I would like to ask, why when i try to open file , that has been sent -
its empty. Size of sent file is proper, but for example when it's pdf -
acrobat reader says " file might be damaged"
Here is my send finction

try
{
if (Client.Connected)
{
this.Text = "Sending File";
String line = null;
file = new FileStream(sfName, FileMode.Open);
fileLength = file.Length;
Client.Client.Send(fName, 0, fName.Length,
SocketFlags.None);

int BytesCount = 0;
mylegth = fileLength / 100;
long i = 0;
this.smoothprogressBar1.Value = 0;
byte[] buffer = new byte[64];

BytesCount = file.Read(buffer, 0, 64);
while ((BytesCount != 0))
{
i += Client.Client.Send(buffer);
this.smoothprogressBar1.Value = (int) ((i *
100)/ fileLength);
BytesCount = file.Read(buffer,0,64);
}

file.Close();
Client.Close();
}
this.Dispose();
}

Dec 15 '05 #1
1 1288
Piotrekk <Pi*************@gmail.com> wrote:
I would like to ask, why when i try to open file , that has been sent -
its empty. Size of sent file is proper, but for example when it's pdf -
acrobat reader says " file might be damaged"
Here is my send finction

try
{
if (Client.Connected)
{
this.Text = "Sending File";
String line = null;
file = new FileStream(sfName, FileMode.Open);
fileLength = file.Length;
Client.Client.Send(fName, 0, fName.Length,
SocketFlags.None);

int BytesCount = 0;
mylegth = fileLength / 100;
long i = 0;
this.smoothprogressBar1.Value = 0;
byte[] buffer = new byte[64];

BytesCount = file.Read(buffer, 0, 64);
while ((BytesCount != 0))
{
i += Client.Client.Send(buffer);


It looks like you're sending the whole buffer, whether or not you've
actually read the whole buffer. See
http://www.pobox.com/~skeet/csharp/readbinary.html

Note that you shouldn't do this kind of thing in the UI thread, and you
shouldn't be updating the UI from any other thread...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by coder_1024 | last post: by
6 posts views Thread by Tung Wai Yip | last post: by
2 posts views Thread by Ebrahim | last post: by
reply views Thread by Richard | last post: by
2 posts views Thread by =?Utf-8?B?QWRl?= | last post: by
5 posts views Thread by Per Juul Larsen | last post: by
maliksleo
1 post views Thread by maliksleo | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.