protected void LinkButton1_Click(object sender, EventArgs e)
{
string fileName = "C#俄罗斯.doc";
[color=#FF0000]string filePath = Server.MapPath("/C#俄罗斯.doc");//路径[/color]
FileStream fs = new FileStream(filePath, FileMode.Open);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
}
关于Server.MapPath()里面怎么写虚拟路径呢?我把文档保存在D:\object\web查询发布\web查询发布\ 里面才能有下载 如果把文档保存在别的地方比如D:\
里面的话在Server.MapPath()里面如何写虚拟路径呢? 麻烦帮下忙!新手不太懂。。
{
string fileName = "C#俄罗斯.doc";
[color=#FF0000]string filePath = Server.MapPath("/C#俄罗斯.doc");//路径[/color]
FileStream fs = new FileStream(filePath, FileMode.Open);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
}
关于Server.MapPath()里面怎么写虚拟路径呢?我把文档保存在D:\object\web查询发布\web查询发布\ 里面才能有下载 如果把文档保存在别的地方比如D:\
里面的话在Server.MapPath()里面如何写虚拟路径呢? 麻烦帮下忙!新手不太懂。。
解决方案 »
- asp.net mvc如何在cs文件里写<%= Html.ActionLink()%>
- 怎么在TreeView每个节点后添加一个button?
- asp.net两个页面传递参数
- RequiredFieldValidator 与 button 的问题
- ====请问如何把“2006/9”的日期格式转化成字符串200609?======
- 请问如何验证LISTBOX,没一个项被选中??帮忙啊,急!!!!!
- 如下代码行为什么错 (用***标注),在线等。
- ReportService2005的问题
- 怎样删除DataGrid的TemplateColumn中CheckBox选中时所返回行的数据??急!!
- WEB api
- asp.net 网站在本地能运行 上传服务器出错!
- web.config配置 allow问题
里面的话在Server.MapPath()里面如何写虚拟路径呢? 麻烦帮下忙!新手不太懂。。
————————————————————————————————————————————————string filePath = "D:\\somefile.doc";如果在其它地方,可以直接把文件路径给filePath变量,不需要再去用Server.MapPath()函数了,直接给文件的路径,其它盘里的也可以,例如:string filePath = "C:\\somefile2.doc";。