sending empty files

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Piotrekk

    #1

    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.Connect ed)
    {
    this.Text = "Sending File";
    String line = null;
    file = new FileStream(sfNa me, FileMode.Open);
    fileLength = file.Length;
    Client.Client.S end(fName, 0, fName.Length,
    SocketFlags.Non e);

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

    BytesCount = file.Read(buffe r, 0, 64);
    while ((BytesCount != 0))
    {
    i += Client.Client.S end(buffer);
    this.smoothprog ressBar1.Value = (int) ((i *
    100)/ fileLength);
    BytesCount = file.Read(buffe r,0,64);
    }

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

  • Jon Skeet [C# MVP]

    #2
    Re: sending empty files

    Piotrekk <Piotr.Kolodzie j@gmail.com> wrote:[color=blue]
    > 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.Connect ed)
    > {
    > this.Text = "Sending File";
    > String line = null;
    > file = new FileStream(sfNa me, FileMode.Open);
    > fileLength = file.Length;
    > Client.Client.S end(fName, 0, fName.Length,
    > SocketFlags.Non e);
    >
    > int BytesCount = 0;
    > mylegth = fileLength / 100;
    > long i = 0;
    > this.smoothprog ressBar1.Value = 0;
    > byte[] buffer = new byte[64];
    >
    > BytesCount = file.Read(buffe r, 0, 64);
    > while ((BytesCount != 0))
    > {
    > i += Client.Client.S end(buffer);[/color]

    It looks like you're sending the whole buffer, whether or not you've
    actually read the whole buffer. See
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.


    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 - <skeet@pobox.co m>
    http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
    If replying to the group, please do not mail me too

    Comment

    Working...