M
Michael Rogers
I wrote a simple file transfer, but it doesn't work!
When I try to open the transferred file it says: "The end of file cropped"
or "the file header cropped". what's wrong with this code? IS there a better
approach?
private void btnGetFile_Click(object sender, System.EventArgs e) {
WebRequest req = WebRequest.Create(txbFile.Text);
try {
WebResponse result = req.GetResponse();
Stream ReceiveStream = result.GetResponseStream();
if(true /* TODO: condition*/) {
FileStream newFile = new FileStream(ResolvePath("temp.zip"),
FileMode.Create);
Byte[] read = new Byte[512];
int bytes = ReceiveStream.Read(read, 0, 512);
while (bytes > 0) {
newFile.Write(read, 0, 512);
bytes = ReceiveStream.Read(read, 0, 512);
}
newFile.Close();
lblResult.ForeColor = Color.Black;
lblResult.Text = "Operation Succeed!";
btnShow.Text = "Download File!";
btnShow.Enabled = true;
}
} catch(Exception _ex) {
lblResult.Text = _ex.ToString();
}
}
Thanks,
- Michael
When I try to open the transferred file it says: "The end of file cropped"
or "the file header cropped". what's wrong with this code? IS there a better
approach?
private void btnGetFile_Click(object sender, System.EventArgs e) {
WebRequest req = WebRequest.Create(txbFile.Text);
try {
WebResponse result = req.GetResponse();
Stream ReceiveStream = result.GetResponseStream();
if(true /* TODO: condition*/) {
FileStream newFile = new FileStream(ResolvePath("temp.zip"),
FileMode.Create);
Byte[] read = new Byte[512];
int bytes = ReceiveStream.Read(read, 0, 512);
while (bytes > 0) {
newFile.Write(read, 0, 512);
bytes = ReceiveStream.Read(read, 0, 512);
}
newFile.Close();
lblResult.ForeColor = Color.Black;
lblResult.Text = "Operation Succeed!";
btnShow.Text = "Download File!";
btnShow.Enabled = true;
}
} catch(Exception _ex) {
lblResult.Text = _ex.ToString();
}
}
Thanks,
- Michael