网站建设中让网站支持txt文件下载
下面这段代码就是可以实现这个功能的,跟大家分享:
string DownloadFilePath ="c:\\file。txt";
Response。Clear();
Response。 ContentType = "application/octet-stream";
Response。AddHeader("Content-Disposition", "attachment; filename=file。 txt" );
Response。Flush();
Response。WriteFile(DownloadFilePath);
下面是代释义:
Response。Clear();方...全部
下面这段代码就是可以实现这个功能的,跟大家分享:
string DownloadFilePath ="c:\\file。txt";
Response。Clear();
Response。
ContentType = "application/octet-stream";
Response。AddHeader("Content-Disposition", "attachment; filename=file。
txt" );
Response。Flush();
Response。WriteFile(DownloadFilePath);
下面是代释义:
Response。Clear();方法删除缓冲区中的所有 HTML 输出。
但 Clear 方法只删除响应正文而不删除响应标题。可以用该方法处理错误情况。请注意,如果未将 Response。Buffer 设置为 TRUE,则该方法将导致运行时错误。
Response。
ContentType = "application/octet-stream";意思是八进制文件更新,是火狐的更新文件,可以下也可以不下,无关紧要,这次没有下载,下次它还会提示你的,没关系。
Response。Flush();的内容至少要有256字节。也就是只有编译产生了至少256字节的数据,才能在执行,以后将信息发到客户端并显示。收起