Solved

.net (vb or c#) file transfer problems

Posted on 2007-11-30
3
211 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
  • 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now