关于页面下载的问题

龙火 2011-03-25 04:47:17
我有一个比较大的PDF格式的文件,我想当用户点击的地址后,弹出让用户能够下载~~
但是点击后页面直接打开这个文件了,老半天才能打开~~
有什么办法能够让用户点击后弹出下载的提示??
其他的方法也可以,在线等!!
...全文
114 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
子夜__ 2011-03-26
  • 打赏
  • 举报
回复
zsyok 2011-03-25
  • 打赏
  • 举报
回复
发送一个头信息
ILOVE_ASPNET 2011-03-25
  • 打赏
  • 举报
回复
以前自己写的一个导出EXCEL 及弹出框保存的例子LZ参考参考

PurchaseOrderParam pop = ReturnParamByUrl();
// pop.PageSize = endIndex;
// IPagedList<PurchaseOrderDetail> list = poService.GetPurchaseOrderDetailList(pop);
// if (list == null)
// return;
// if (list != null)
// {
// System.Web.HttpContext curContext = System.Web.HttpContext.Current;
// curContext.Response.Clear();
// if (endIndex <= 0 || endIndex > list.TotalCount)
// endIndex = list.TotalCount;
// // 设置编码和附件格式
// curContext.Response.ContentType = "application/vnd.ms-excel";
// curContext.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
// curContext.Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode(fileName, Encoding.GetEncoding("gb2312")) + "." + fileType);
// curContext.Response.Flush();
// StringBuilder sb = new StringBuilder();
// StringBuilder sbline = new StringBuilder();
// string coltmp = fileType.ToLower() == "csv" ? "\"{0}\"," : "{0},";
// int itemp = 0;
// XmlDocument doc = new XmlDocument();
// doc.Load(Server.MapPath("~/App_Data/ExportFormart.xml"));
// XmlNodeList xmlNodeList = doc.SelectNodes("//FileFormats/FileFormat[@TbColumn='" + column + "']/Field[@Display='True']");
// foreach (XmlNode xdcolName in xmlNodeList)
// sbline.Append(string.Format(coltmp, xdcolName.Attributes["Description"].Value));
// if (sbline.Length == 0)
// return;
// sbline.ToString().Remove(sbline.Length - 1);
// sb.AppendLine(sbline.ToString());
// sbline.Remove(0, sbline.Length);
// foreach (PurchaseOrderDetail pod in list.InnerList)
// {
// if (itemp == endIndex)
// break;
// sbline.Remove(0, sbline.Length);
// foreach (XmlNode xdcolValue in xmlNodeList)
// {
// string fieldName = xdcolValue.Attributes["Name"].Value;
// if (!string.IsNullOrEmpty(fieldName))
// {
// object value;
// PropertyInfo p = pod.GetType().GetProperty(fieldName);
// if (p == null)
// {
// Entity.Goods gd = new Entity.Goods();
// gd = pod.Goods;
// value = gd.GetType().GetProperty(fieldName).GetValue(gd, null);
// }
// else
// value = p.GetValue(pod, null);
// if (value == null)
// {
// sbline.Append(string.Format(coltmp, ""));
// continue;
// }
// else
// {
// if (fieldName == "Status")
// {
// if (value.ToString() == "1") value = "未处理";
// else if (value.ToString() == "2") value = "已处理";
// else if (value.ToString() == "3") value = "取消";
// else if (value.ToString() == "4") value = "结案";
// }
// }
// sbline.Append(string.Format(coltmp, value.ToString()));
// }
// }
// sb.AppendLine(sbline.ToString());
// itemp++;
// }
// curContext.Response.Write(sb.ToString());
// curContext.Response.End();
// }
Corporal 2011-03-25
  • 打赏
  • 举报
回复
能做个压缩包多好,点了就下了,不会打开啊!
KeepMoving 2011-03-25
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 tao145 的回复:]
C# code

string path = Server.MapPath(@"~\file\test.pdf");
HttpResponse response = HttpContext.Current.Response;
response.Clear();
res……
[/Quote]++
龙火 2011-03-25
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 tao145 的回复:]
C# code

string path = Server.MapPath(@"~\file\test.pdf");
HttpResponse response = HttpContext.Current.Response;
response.Clear();
……
[/Quote]
请问这代码我放在哪?
我是想点击链接让后弹出下载框
笑道江湖情 2011-03-25
  • 打赏
  • 举报
回复
path 是文件的物理路径
笑道江湖情 2011-03-25
  • 打赏
  • 举报
回复

string path = Server.MapPath(@"~\file\test.pdf");
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.ClearHeaders();
response.Buffer = true;
Encoding code = Encoding.GetEncoding("GB2312");
response.ContentEncoding = code;
response.HeaderEncoding = code;
response.AddHeader("Content-Type", "application/octet-stream");
response.AppendHeader("Content-Disposition", "filename=test.pdf");
response.WriteFile(path);
response.Flush();
response.Close();
龙火 2011-03-25
  • 打赏
  • 举报
回复
快来人啦!!
龙火 2011-03-25
  • 打赏
  • 举报
回复
没人顶,我自己顶下。
我记得其他文件点击路径是可以弹出提示下载的!!

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧