如题
解决方案 »
- 如何将CalendarExtender today翻译成中文
- 将html页面怎么很好的改成aspx
- Image图片绝对路径问题
- 本地调试以后是正常的.发布到网上出现的错误
- 请问各位,怎样才能使敲“回车”键后不激发“button”控件,只有在用鼠标点"button"时才激发,谢谢
- 学习duwamish时候碰到的疑问,高手们来解答下吧~~
- 2个Calendar控件,只能有一个控件可以选择日期???
- Infragistics webgrid和webcombo在客户端添加新行怎么写啊
- 请问如何用Session来储存一个DataSet
- 关于在Button的Attributes属性的Add方法中添加JavaScript脚本的问题!谢谢帮忙!
- 关于MapXtreme2.5在ASP.NET上创建服务器端对象的问题
- web控件就无法相应客户端事件了吗?
/// 文件下载
/// </summary>
/// <param name="FullFileName"></param>
private void FileDownload(string FullFileName)
{
FileInfo DownloadFile = new FileInfo(FullFileName);
Response.Clear();
Response.ClearHeaders();
Response.Buffer=false;
Response.ContentType="application/octet-stream";
Response.AppendHeader("Content-Disposition","attachment;filename=" +HttpUtility.UrlEncode(DownloadFile.FullName,System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length",DownloadFile.Length.ToString());
Response.WriteFile(DownloadFile.FullName);
Response.Flush();
Response.End();
}
2.可以使用代码实现下载文件出现提示框或者直接显示在浏览器中
出现提示框string strFile="F:\\a.doc";//路径根据实际情况而定
if(!System.IO.File.Exists(strFile))
{
Response.Write("<script language='javascript'>alert('对不起,文件不存在!');</script>");
return;
}
Response.Clear();
Response.ClearHeaders();
Response.Charset = "GB2312";
Response.ContentEncoding =System.Text.Encoding.UTF8;
Response.ContentType = "application/octet-stream";
FileInfo fi=new FileInfo(strFile);
Response.AddHeader("Content-Disposition","attachment; filename=" + HttpUtility.UrlEncode(fi.Name)) ;
Response.AddHeader("Content-Length",fi.Length.ToString());
byte[] tmpbyte=new byte[1024*8];
FileStream fs=fi.OpenRead();
int count;
while((count=fs.Read(tmpbyte,0,tmpbyte.Length))>0)
{
Response.BinaryWrite(tmpbyte);
Response.Flush();
}
fs.Close();
Response.End();直接在浏览器中打开
string strFile="F:\\a.doc";//路径根据实际情况而定
Response.Clear();
Response.ClearHeaders();
Response.Charset = "GB2312";
Response.ContentEncoding =System.Text.Encoding.UTF8;
Response.ContentType = "application/msword";
Response.WriteFile(strFile);
你可以改变文件的扩展名,如doc改为 docc
而这些设置需要在客户端进行.
所以,你只能告诉用户,想要直接在WORD里面打开文件,最好直接下载到本地,然后再打开,不要在网页里面直接点击.
Response.AddHeader("Content-Disposition", "attachment;FileName="+YourFileName);
Response.BinaryWrite((byte[])YourFileData.Rows[0]["AttachmentContent"]);
Response.End();