Save a zip file locally?

M

Michael Rogers

I dunno how save a file locally! How can I copy a file
(http://foo.com/foo.zip) to my local server
(http://mydomain.com/temp/foo.zip)?

I saw a sample in MS Quick Start but I can't manipulate it to work with for
example zip files.

WebRequest req = WebRequest.Create(txbFile.Text);

try {
WebResponse result = req.GetResponse();
Stream ReceiveStream = result.GetResponseStream();
if(true) {
StreamWriter writer = new StreamWriter(ResolvePath("temp.zip"));

Byte[] read = new Byte[512];
int bytes = ReceiveStream.Read(read, 0, 512);

// int i = ReceiveStream.ReadByte();
while (bytes > 0) {
writer.Write(bytes);
bytes = ReceiveStream.Read(read, 0, 512);
}
// while(i != -1){
// writer.Write(i);
// i = ReceiveStream.ReadByte();
// }
writer.Close();
lblResult.ForeColor = Color.Black;
lblResult.Text = "Operation Succeed!";
btnShow.Text = "Download File!";
btnShow.Enabled = true;
}
} catch(Exception _ex) {
lblResult.Text = _ex.ToString();
}

TIA
- Michael Rogers
 
D

DaveJohnson12

I dunno how save a file locally! How can I copy a file
(http://foo.com/foo.zip) to my local server
(http://mydomain.com/temp/foo.zip)?

I saw a sample in MS Quick Start but I can't manipulate it to work with for
example zip files.

WebRequest req = WebRequest.Create(txbFile.Text);

try {
WebResponse result = req.GetResponse();
Stream ReceiveStream = result.GetResponseStream();
if(true) {
StreamWriter writer = new StreamWriter(ResolvePath("temp.zip"));

Byte[] read = new Byte[512];
int bytes = ReceiveStream.Read(read, 0, 512);

// int i = ReceiveStream.ReadByte();
while (bytes > 0) {
writer.Write(bytes);
bytes = ReceiveStream.Read(read, 0, 512);
}
// while(i != -1){
// writer.Write(i);
// i = ReceiveStream.ReadByte();
// }
writer.Close();
lblResult.ForeColor = Color.Black;
lblResult.Text = "Operation Succeed!";
btnShow.Text = "Download File!";
btnShow.Enabled = true;
}
} catch(Exception _ex) {
lblResult.Text = _ex.ToString();
}

TIA
- Michael Rogers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top