您当前的位置: 首页 >  .net

[Asp.Net]在线阅读文件

发布时间:2011-01-28 12:46:00 ,浏览量:0

string fileName = "201096218686"; string p = "201096198974.pdf";//定义文件名 string filePath = Server.MapPath("DataFile/" + p);//转换为物理路径 Response.ClearContent();//清空缓冲区内容 Response.ClearHeaders();//清空缓冲区HTTP头 string FilePost = filePath.Substring(filePath.Length - 3).ToLower();//取扩展名 switch (FilePost) { case "pdf"://PDF文件 Response.ContentType = "application/PDF";//设置HTTP头为PDF文档其它类似 break; case "doc": Response.ContentType = "application/msword"; break; case "xls": Response.ContentType = "application/vnd.ms-excel"; break; default: Session["ErrorInfo"] = "不支持的文件格式:" + FilePost; Response.Redirect("ErrorPage.aspx"); break; } Response.WriteFile(filePath);//写入客户端 Response.Flush();//客户更新 Response.Close();//写入关闭 Session.Remove("Report");//移除"Report"Session

关注
打赏
1688896170
查看更多评论

暂无认证

  • 0浏览

    0关注

    103078博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0470s