|
It ’s like this, I wrote the following code, a text file on the server, now this text file does exist, and this code is local, my other 2 web servers (win2k3) are ok, only in it When a web server is downloaded, the text file is empty-there is no content, please help!
private void DownloadTemplate (string filepath)
{
System.IO.Stream iStream = null;
byte [] buffer = new Byte [10000];
int length;
long dataToRead;
string filename = System.IO.Path.GetFileName (filepath);
try
{
if (! System.IO.File.Exists (filepath))
return;
iStream = new System.IO.FileStream (filepath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read); // Total bytes to read:
dataToRead = iStream.Length;
Response.ContentType = "application / octet-stream";
Response.AddHeader ("Content-Disposition", "attachment; filename =" + HttpUtility.UrlEncode (filename, System.Text.Encoding.UTF8)); // Read the bytes.
while (dataToRead> 0)
{// Verify that the client is connected.
if (Response.IsClientConnected)
{// Read the data in buffer.
length = iStream.Read (buffer, 0, 10000); // Write the data to the current output stream.
Response.OutputStream.Write (buffer, 0, length); // Flush the data to the HTML output.
Response.Flush ();
buffer = new Byte [10000];
dataToRead = dataToRead-length;
}
else
{
dataToRead = -1;
}
}
}
catch (Exception ex)
{
showError ("", "StyleDef.ascx", "DownloadTemplate", "", "Fail: doing download for stylefile. message:" + ex.Message, "");
}
finally
{
if (iStream! = null)
{// Close the file.
iStream.Close ();
}
Response.Close ();
}
} |
|