Tech
Forums
Jobs
Books
Events
Videos
Conference
Annual Conference
Bcrypt
Ai Conference
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
3
Answers
Downloading zip files.
Ask a question
Ask a question
Upload Source Code:
Select only zip and rar file.
rick
18y
2.3k
1
Reply
Hey guys,
Ive been having a problem downloading files through a proxy server. it worked fine while i was downloading small test files (zip files to be exact < 5kb) but when i use actual files, they are always corrupt on the client side, but when you open the zip file there are never more than 2 files present and they are corrupt as well. any help would be greatly appreciated.
Thanks,
here is
a before and after screen shot
of the zip files, if that helps, and the following is a code snippit.
public void BeginDownload(){
WebProxy
proxy
=
new
WebProxy
(
ServPath,
true
);
proxy
.
Credentials
=
new
NetworkCredential
(
UserName,
Pass);
WebRequest
request
=
WebRequest
.
Create(
ServPath + FileName);
request
.
Proxy
=
proxy;
// Send the 'HttpWebRequest' and wait for response.
HttpWebResponse
response
=
(
HttpWebResponse
)request
.
GetResponse();
System
.
IO
.
Stream
stream
=
response
.
GetResponseStream();
FileStream
writeStream
=
new
FileStream
(Download
Path + FileName,
FileMode
.
Create,
FileAccess
.
Write);
ReadWriteStream(stream, writeStream, response
.
ContentLength);
response
.
Close();
}
private
void
ReadWriteStream(
Stream
readStream,
Stream
writeStream,
long
lLength)
{
int
Length
=
Convert
.
ToInt32(lLength);
Byte
[] buffer
=
new
Byte
[Length
+
(
100
-
Length
%
100
)
+
5
];
int
numBytesToRead
=
Length;
int
numBytesRead
=
0
;
while
(numBytesToRead
>
0
)
{
int
n;
n
=
readStream
.
Read(buffer, numBytesRead, numBytesToRead);
WriteStream
.
Write(buffer, numBytesRead, numBytesToRead);
numBytesRead
+=
n;
numBytesToRead
-=
n;
}
readStream
.
Close();
writeStream
.
Close();
}
Post
Reset
Cancel
Answers (
3
)
Next Recommended Forum
textbox enter
'HttpContext' does not exist in the class or...