473,320 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 1349
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: coder_1024 | last post by:
I'm trying to send a packet of binary data to a UDP server. If I send a text string, it works fine. If I attempt to send binary data, it sends a UDP packet with 0 bytes of data (just the...
6
by: Tung Wai Yip | last post by:
Can I add empty directory using zipfile? When I try to add a directory it complains that it is not a file. tung
2
by: Ebrahim | last post by:
Does any one have any suggestion of Sending Files over a Network ? using TcpClient class in C#. I need suggestions on transferring huge files ( > 5MB) reliably over the stream . Also any kind of...
0
by: Richard | last post by:
First some background... I have an application whereby I send a mail, attach some attachments stored in the windows/temp directory and then send them. This works fine on 2 servers both are not...
0
by: remya1000 | last post by:
by using FTP i can send files to server using vb.net. if the file is big, then it will take some time to complete the sending process to server.or if we were sending 3-4 files to the server one by...
2
by: =?Utf-8?B?QWRl?= | last post by:
HI All, I am encountering the following error when I try to send an email through a SMTP server. I believe the problem lies with the authentication part when the network crednetials are used,...
2
by: satnamsarai | last post by:
Using System.Net.Mail: Sometimes I get error 'failure sending mail. Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.' Not sure how...
5
by: Per Juul Larsen | last post by:
Hi. My application creates empty libraries. How do I ensure that the user copies at least one or more picture files (.jpg) in each of the empty folders ? Result , no empty folders! regards pjl
1
maliksleo
by: maliksleo | last post by:
hi i am using the following class for email sending but getting this error "Failure sending mail" Imports System.Net.Mail Public Class MailHelper ''' <summary> ''' Sends an mail...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.