protected void LinkButton1_Click(object sender, EventArgs e)
{
if (Session["txt"] != null)
{
string fileName = "";//客户端保存的文件名
string filePath = Server.MapPath("./") + fileName;//路径 FileInfo fileInfo = new FileInfo(filePath);
if (fileInfo.Exists)
{
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
Response.AddHeader("Content-Length", fileInfo.Length.ToString());
Response.AddHeader("Content-Transfer-Encoding", "binary");
Response.ContentType = "application/octet-stream";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
Response.WriteFile(fileInfo.FullName);
Response.Flush();
Response.End();
}
}
else
{
Page.RegisterStartupScript("sb", "<script>alert('请先选择文件名')</script>");
} }
代码如上,必须将红色代码改成如下形式,
string filePath = Server.MapPath("申请书.doc");
才能下载下来,而其他格式的文件则下载不下来 或者下载下来是不能打开。
问题是怎么修改可以下载任何格式,而不是只下载一个格式或一个文件,
文件的下载过程中用了 ListBox控件。
{
if (Session["txt"] != null)
{
string fileName = "";//客户端保存的文件名
string filePath = Server.MapPath("./") + fileName;//路径 FileInfo fileInfo = new FileInfo(filePath);
if (fileInfo.Exists)
{
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
Response.AddHeader("Content-Length", fileInfo.Length.ToString());
Response.AddHeader("Content-Transfer-Encoding", "binary");
Response.ContentType = "application/octet-stream";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
Response.WriteFile(fileInfo.FullName);
Response.Flush();
Response.End();
}
}
else
{
Page.RegisterStartupScript("sb", "<script>alert('请先选择文件名')</script>");
} }
代码如上,必须将红色代码改成如下形式,
string filePath = Server.MapPath("申请书.doc");
才能下载下来,而其他格式的文件则下载不下来 或者下载下来是不能打开。
问题是怎么修改可以下载任何格式,而不是只下载一个格式或一个文件,
文件的下载过程中用了 ListBox控件。
解决方案 »
- 请问用什么数据结构保存省份以及对应的URL?
- 调用WebService返回xml问题,急!~~~
- 大侠帮忙:未能加载文件或程序集“Microsoft.Data.SqlXml……
- 数据填充时sql数据类型转换问题,急!在线等待
- Response.Write(DateTime.Now.ToString("yyyy-MM-dd hh:mm tt"));
- 异常详细信息: System.Data.OleDb.OleDbException: 至少一个参数没有被指定值
- 100分求助字符串相等的问题,顶者有分
- 怎么把第一次访问生成的静态页面保存下来
- ASP.NET该怎么学?请教一下各位高手
- 用asp.net怎么实现幻灯片效果
- girdview在服务器上生成excel不知道怎么第一行出现一个?号
- 网站重命名后,如何读取asp.net网站管理工具的数据。
没有赋值为文件名
没有赋值为文件名
应该是考虑把这个改成动态的吧。不是的格式,流转化似乎不一样。