解决方案 »
- (findcontrol)希望知道的人可以快点给予答复
- asp.net(C#)开发的网站,在winServer2008 IIS上发布后其中的发送邮件功能失效,怎么解决?
- 弹出窗体传值问题
- 请问 c# 程序中控制控件的焦点, 是通过JavaScript来实现, 还是其他方法......
- 在线录音的实现
- 一个关于DataGrid的问题
- 为什么自定义的配置节需要这么多信息?
- 求助: webform 控件 布局
- 另人疑惑的DetailsView问题
- ==》求教:关于asp.net中集成word编辑文本?有教程文档者 特谢!
- js生成表格如何将数据绑定,谢谢
- 求一个正则表达式,用来实现二级域名,当二级是www或以n结尾的不重写,因为是保留二级
{
HttpContext.Current.Response.ContentType = "text/html";
string filename = path.Substring(path.LastIndexOf("/")+1);
HttpContext.Current.Response.AddHeader("Content-Disposition","attachment;filename="+filename);
//**指定编码,防止中文文件名乱码
HttpContext.Current.Response.HeaderEncoding = System.Text.Encoding.GetEncoding("gb2312");
HttpContext.Current.Response.TransmitFile(path);
}
catch{throw;}
这个你真的应该自己去了解一下啊。我不负责帮写作业的哦。其实设置成别的什么(哪怕是错的),也一样解决你的问题的。例如application/vnd.android.package-archive
video/x-msvideo
application/msword
application/msword
video/x-flv
image/gif
image/x-icon
application/vnd.ios.package-archive
image/jpeg
image/jpeg
pplication/javascript
image/png
text/plain
application/vnd.ms-powerpoint
application/vnd.ms-powerpoint
application/vnd.ms-powerpoint
application/vnd.ms-powerpoint
application/vnd.openxmlformats-officedocument.presentationml.presentation
application/vnd.openxmlformats-officedocument.presentationml.template
application/vnd.openxmlformats-officedocument.presentationml.slideshow
application/vnd.ms-powerpoint.addin.macroEnabled.12
application/vnd.ms-powerpoint.presentation.macroEnabled.12
application/vnd.ms-powerpoint.presentation.macroEnabled.12
application/vnd.ms-powerpoint.slideshow.macroEnabled.12
application/x-silverlight-app
application/vnd.ms-excel
application/vnd.ms-excel
application/vnd.ms-excel
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
application/vnd.openxmlformats-officedocument.spreadsheetml.template
application/vnd.ms-excel.sheet.macroEnabled.12
application/vnd.ms-excel.template.macroEnabled.12
application/vnd.ms-excel.addin.macroEnabled.12
application/vnd.ms-excel.sheet.binary.macroEnabled.12任选一个你认为接近的好了。实在不知道,就写 application/octet-stream。
这个你真的应该自己去了解一下啊。我不负责帮写作业的哦。其实设置成别的什么(哪怕是错的),也一样解决你的问题的。例如application/vnd.android.package-archive
video/x-msvideo
application/msword
application/msword
video/x-flv
image/gif
image/x-icon
application/vnd.ios.package-archive
image/jpeg
image/jpeg
pplication/javascript
image/png
text/plain
application/vnd.ms-powerpoint
application/vnd.ms-powerpoint
application/vnd.ms-powerpoint
application/vnd.ms-powerpoint
application/vnd.openxmlformats-officedocument.presentationml.presentation
application/vnd.openxmlformats-officedocument.presentationml.template
application/vnd.openxmlformats-officedocument.presentationml.slideshow
application/vnd.ms-powerpoint.addin.macroEnabled.12
application/vnd.ms-powerpoint.presentation.macroEnabled.12
application/vnd.ms-powerpoint.presentation.macroEnabled.12
application/vnd.ms-powerpoint.slideshow.macroEnabled.12
application/x-silverlight-app
application/vnd.ms-excel
application/vnd.ms-excel
application/vnd.ms-excel
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
application/vnd.openxmlformats-officedocument.spreadsheetml.template
application/vnd.ms-excel.sheet.macroEnabled.12
application/vnd.ms-excel.template.macroEnabled.12
application/vnd.ms-excel.addin.macroEnabled.12
application/vnd.ms-excel.sheet.binary.macroEnabled.12任选一个你认为接近的好了。实在不知道,就写 application/octet-stream。
好的.thanks..
ContentType 设置成这个 application/octet-stream 后
本来应该是a.jpg 但是变成了a.html了。。
//引入命名空间
using System.IO;
//加载自定义方法
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)//首次加载
{
addListBox(); //调用用户自定义的addListBox方法
}
}
//自定义方法绑定控件
protected void addListBox()
{
//将指定文件夹中的文件保存到字符串数组中
string[] name = Directory.GetFiles(Server.MapPath("File"));
foreach (string s in name)
{
//将文件名添加到ListBox中
LisBoxFile.Items.Add(Path.GetFileName(s));
}
}
//把控件赋值给变量
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
Session["txt"] = LisBoxFile.SelectedValue.ToString();//从ListBox控件中选择的项赋值给Session["txt"]中
}
//获取下载路径下载文件
protected void dFile()
{
//判断是否选择文件名
if (LisBoxFile.SelectedValue != "")
{
if (Session["txt"] != "")
{ //获取文件路径
string path = Server.MapPath("File/") + Session["txt"].ToString();
//初始化 FileInfo 类的实例,它作为文件路径的包装
FileInfo fi = new FileInfo(path);
//判断文件是否存在
if (fi.Exists)
{
//将文件保存到本机上
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(fi.Name));
Response.AddHeader("Content-Length", fi.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.Filter.Close();
Response.WriteFile(fi.FullName);
Response.End();
}
}//CodeGo.net/
}
else
{
Page.RegisterStartupScript("sb", "<script>alert('请您先选择文件名')</script>");
}
}
//把需要下载的文件保存到本地磁盘
protected void ImgBtnDownFile_Click(object sender, ImageClickEventArgs e)
{
dFile();//调用用户自定义的dFile方法,实现
}
//断点续传跳转页面(略)