Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / December 2005

Tip: Looking for answers? Try searching our database.

sending empty files

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Piotrekk - 15 Dec 2005 19:18 GMT
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();
           }
Jon Skeet [C# MVP] - 17 Dec 2005 17:51 GMT
> 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 -
[quoted text clipped - 22 lines]
>                     {
>                         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...

Signature

Jon Skeet - <skeet@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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.