471,315 Members | 2,253 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

File sent only partially

Hi
I have a question.
Why file, that i wanna send is sent only partially.
When i wanna send 4xx kb only 266 is sent.
Thanks for your help
PK

Here is the code:

if (Client.Connected)
{
String line = null;
file = new StreamReader(sfName);
fileLength = file.BaseStream.Length;
Client.Client.Send(fName, 0, fName.Length,
SocketFlags.None);
mylegth = fileLength / 100;
long i = 0;
this.smoothprogressBar1.Value = 0;

while ((line = file.ReadLine()) != null)
{
i +=
Client.Client.Send(ASCIIEncoding.ASCII.GetBytes(li ne));
this.smoothprogressBar1.Value = (int) ((i *
100)/ fileLength);
}

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

Dec 2 '05 #1
1 1175
Piotrekk wrote:
I have a question.
Why file, that i wanna send is sent only partially.
When i wanna send 4xx kb only 266 is sent.


Well, the first problem is that you're reading the file as a text file
with an ASCII encoding. If the file contains any non-ASCII data, you'll
be losing it. Why not just send it as binary data in the first place?

The second problem I can see is that you're not sending the line
terminators.

Beyond that, it's somewhat hard to tell, particularly as we don't know
the type of "Client".

Could you post a short but complete example which demonstrates the
problem?
See http://www.pobox.com/~skeet/csharp/complete.html for details on
what I mean by that.

Jon

Dec 2 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Bill Belliveau | last post: by
2 posts views Thread by SoSaucily | last post: by
35 posts views Thread by keerthyragavendran | 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.