出于某种原因,当我显示另存为对话框时,我的校验和框永远不会更新。但是,如果我注释掉下面的 Content-Disposition 标头代码,那么一切正常。有任何想法吗?
protected void SubmitButton_Click(object sender, EventArgs e)
{
checksumField.Text = String.Empty;
FileInfo filename = this.CreateFileInfoFromInput();
if (!filename.Exists)
{
tableField.Focus();
tableField.BorderColor = System.Drawing.Color.Red;
return;
}
this.SaveFile(filename);
checksumField.Text = GetChecksum(filename);
}
private FileInfo CreateFileInfoFromInput()
{
/* blah */
return new FileInfo(blah);
}
private string GetChecksum(FileInfo filename)
{
return "test";
}
private void SaveFile(FileInfo fileName)
{
// Clear old headers
Response.Clear();
Response.Buffer = false;
// Set the ContentType and Headers
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName.Name); // <<<---- FAILING RIGHT HERE
Response.AppendHeader("Content-Length", fileName.Length.ToString(System.Globalization.CultureInfo.InvariantCulture));
Response.AppendHeader("Connection", "Keep-Alive");
// Send data
Response.TransmitFile(fileName.FullName);
}