Solved

.net (vb or c#) file transfer problems

Posted on 2007-11-30
3
215 Views
Last Modified: 2013-12-16
Here is the paste bin of my code: http://pastebin.com/m5b4d4d85

Here is the problem:
1 - im trying to make it so I can transfer large files. I have it now to the point it "thinks" its sending the large file but its always corrupt do to sending to many bytes. It seems when I change the "Dim blocksize As Int16 = 1000" to a different number such as 8000 it either gets it closer to the right file size or farther away if that makes sense. So have to figure out why its doing that.

2 - testing on a small file 1kb zip file. When it transfers it, I can open it up and view my text file inside the zip and everything works fine except that the transfered zip is now 3kb not 1kb like the original. So have to figure this out as well dont make sense to me.

Im new to this networking stuff so bare with me as this code is probably "gross" but any help would be greatly appreciated.

Thank You!
0
Comment
Question by:aumudin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 500 total points
ID: 20388093
Here is your problem:

thisread = fileStream.Read(dataByte, 0, blocksize)
networkStream.Write(dataByte, 0, dataByte.Length)

The Read method returns the number of bytes read. You ignore this value and just write the entire content of the buffer regardless of how much of the buffer was actually used.

Change if to only write the actual data that you got:

thisread = fileStream.Read(dataByte, 0, blocksize)
If thisread > 0 Then
   networkStream.Write(dataByte, 0, thisread)
End If
0
 
LVL 4

Author Comment

by:aumudin
ID: 20388167
Perfect! Thank you very much
0
 
LVL 4

Author Closing Comment

by:aumudin
ID: 31412078
TY
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question