//生成一个文件并提供下载
private void Button1_Click(object sender, System.EventArgs e)
{
//显示进度条
string jsBlock="<script>div1.style.visibility='visible';</script>";
Page.RegisterClientScriptBlock("jsBlock1",jsBlock);
//生成一个文件
...
//隐藏进度条
jsBlock="<script>div1.style.visibility='hidden';</script>";
Page.RegisterClientScriptBlock("jsBlock2",jsBlock);
//提供下载
if(File.Exists(Path.Combine(path,file)))
{
FileInfo DownloadFile=new FileInfo(Path.Combine(path,file));
Response.Clear();
Response.ClearHeaders();
Response.Buffer=false;
Response.ContentType="application/octet-stream";
Response.AppendHeader("Content-Disposition","attachment;filename="+HttpUtility.UrlEncode(DateTime.Now.ToString("yyyyMMdd")+"("+Session["dwmc"].ToString()+").doc",System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length",DownloadFile.Length.ToString());
Response.WriteFile(DownloadFile.FullName);
Response.Flush();
Response.End();
}运行后网页错误提示:服务器无法在发送HTTP标头之后清除标头。提示在
Response.ClearHeaders();
和
Response.ContentType="application/octet-stream";
出错。请问大虾怎么解决这个问题?
private void Button1_Click(object sender, System.EventArgs e)
{
//显示进度条
string jsBlock="<script>div1.style.visibility='visible';</script>";
Page.RegisterClientScriptBlock("jsBlock1",jsBlock);
//生成一个文件
...
//隐藏进度条
jsBlock="<script>div1.style.visibility='hidden';</script>";
Page.RegisterClientScriptBlock("jsBlock2",jsBlock);
//提供下载
if(File.Exists(Path.Combine(path,file)))
{
FileInfo DownloadFile=new FileInfo(Path.Combine(path,file));
Response.Clear();
Response.ClearHeaders();
Response.Buffer=false;
Response.ContentType="application/octet-stream";
Response.AppendHeader("Content-Disposition","attachment;filename="+HttpUtility.UrlEncode(DateTime.Now.ToString("yyyyMMdd")+"("+Session["dwmc"].ToString()+").doc",System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length",DownloadFile.Length.ToString());
Response.WriteFile(DownloadFile.FullName);
Response.Flush();
Response.End();
}运行后网页错误提示:服务器无法在发送HTTP标头之后清除标头。提示在
Response.ClearHeaders();
和
Response.ContentType="application/octet-stream";
出错。请问大虾怎么解决这个问题?
解决方案 »
- FCKeditor上传图片的时候怎样让图片是相对路径
- 小D想声明一个ajaxtoolkits控件的数组应该如何做?
- 删除问题,大家帮忙看下
- 类库项目中怎样才能显示所引用的DLL文件?
- 让aspxspy木马报废的方法!
- 一个存储过程,既返回了一个记录集,又返回了一个输出参数,但调用时只取得记录集,没有取得输出参数值,如何调用一次同时取得记录集和输
- 用c#如何实现将生成的XML文件自动下载到客户端指定目录?
- 关于ASP.NET 进行在线截屏[2.0] C#
- 百思不得其解,谁知道这种Url搜索是怎么实现的?
- 关于DataGrid的CheckBox的问题?
- 能在Javascript中指定使用哪个CSS吗? (在线~ 有答案立刻结帖)
- SqlDataSource1 修改参数后怎么没数据返回,请高手指点迷津
{
FileStream stream=null;
stream = new FileStream(physicalFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
int bufSize = (int)stream.Length;
byte[] buf = new byte[bufSize]; int bytesRead = stream.Read(buf, 0, bufSize);
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename="+System.IO.Path.GetFileName(physicalFilePath));
HttpContext.Current.Response.OutputStream.Write(buf, 0, bytesRead);
HttpContext.Current.Response.End();
}
要显示进度条的话,另开一页应该是个办法。可以试试。
string jsBlock="<script>div1.style.visibility='visible';</script>";
Page.RegisterClientScriptBlock("jsBlock1",jsBlock);
//生成一个文件
...
//隐藏进度条
jsBlock="<script>div1.style.visibility='hidden';</script>";
Page.RegisterClientScriptBlock("jsBlock2",jsBlock);这两个jsBlock根本没有被发送到客户端。
如下是可行的,两个jsBlock可以被发送到客户端,能被执行: string jsBlock="<script>div1.style.visibility='visible';</script>";
Page.RegisterClientScriptBlock("jsBlock1",jsBlock);
for(int i=0;i<100000;i++)
for(int j=0;j<10000;j++){//do}
//隐藏进度条
jsBlock="<script>div1.style.visibility='hidden';</script>";
Page.RegisterClientScriptBlock("jsBlock2",jsBlock);到此为止,下面不发送文档。我也觉得奇怪,为什么加了发送文档的代码后,jsBlock没有被发送?哪位高人能解释一下。